#trying to make an efficient way to sort through table
1 messages · Page 1 of 1 (latest)
** You are now Level 4! **
am lost
who are these players and why they got special alien
** You are now Level 5! **
thats me and my friends cuz i want to have an exclusive alien for me and my friends
or for like moderators
but it'll prolly be changed to alienX instead of waybig
then use a datastore preferably or a table if it wont change very often
this is in a serverside script
and?
well im just saying
im looking for a solution to this table problem
cuz
this is my first time attempting using tables
?
yeah i know but how would i do the thing im trying to do
i want to be able to press E or Q to shift onto the next string in the table
wait so what is the problem? selecting an alien or the friends check? or both..?
the friends check is completely fine
im trying to make a way to shift through the table
rn the script moves the selected alien to the last alien in the table
ok so basically you are going to be making a linked list type of structure
yep and how would i do that
have the aliens available on the client side. then have a starting index. whenever the player presses E or Q the index will increase or decrease by 1 and the selected alien will be the one that corresponds to the index. whenever the index moves to either the last or first index of the table, you will get a range error if you decrease/increase it again. thus you can choose whether the user is unable to select any more aliens to the left/right or you can make it so that if they go too far to the left, they will start selecting from the right and vice versa. then they can just use remote to fire to server which alien they want
search up linked list if my explanation bad
i think i'd rather keep the table on the server side, idm if it lags i just dont want vulnerabilities with exploits
it wont have exploits. the user will simply dial which alien they want on the client side, then fire the one they want to the server and the server does security checks
table.find 
thankyou pyro
no
just access it by index
it returns index or nil
how
table.find returns the index, not a bool. https://create.roblox.com/docs/reference/engine/libraries/table#find 
if you already have table key/index then just tbl[key] 
what is the solution this is all so confusing
;compile lua lua local t={cat="c"} print(table.find(t,"c")) -- cat
/opt/wandbox/lua-5.4.7/bin/lua: prog.lua:2: attempt to call a nil value (field 'find')
stack traceback:
prog.lua:2: in main chunk
[C]: in ?
what does this mean, can you explain it a bit
table.find searches for a key
In table
in list-like it's different
btw better to use mapping table
no it searches for a value
only works in an array
you can traverse the table with a function like this: (sorry for shit formatting im on mobile)
local START_INDEX = 1
local function Traverse(T, increment)
local Index = START_INDEX + increment
if t[Index] then return t[Index] end
if Index < 1 then
return table.maxn(t)
else
return t[1]
end
end
(idk if this works i cant test 🙏)
local t={"a","b","cat","e"}
print(table.find(t,"cat")) -- 3
https://create.roblox.com/docs/reference/engine/libraries/table#find
Within the given array-like table haystack
now it's right
i thought it also worked for dicts. good to know 
I think it would be confusing