i believe table.find() returns numerical indexes
so if you tried to find something that doesn’t have a number for the index (“player1” = Drixitty) it would return nil not “player1”
local Fruit = {
["Fruit1"] = "Apple";
["Fruit2"] = "Banana";
}
print(table.find(Fruit, "Apple")) --> nil
local Fruit = {
[1] = "Apple";
[2] = "Banana";
}
print(table.find(Fruit, "Apple")) --> 1
yeah that makes sense and that was the issue, but how should i go about doing this then? i’m trying to get the current player and then go to the next player in the table, i’m trying to make turns
You might want to use for loop, loop through all values inside the table and if the value of one of them (which is the player) is equal to the player variable which we already had from PlayerAdded event, we set the foundPlr to the key so you can use it later.
local foundPlr
local function endTurn()
for key, value in players do
if value == player then
foundPlr = key
break
end
end
end
basically, the key is the name of the value inside the table, and value is the value of the name that is inside the table too.
function table.Find(Table,index)
assert(Table)
Count=0
for i,v in pairs(Table) do Count+=1;end
for i,v in next,Table do
if i==index then
return rawget(Table,i)
elseif i==#Count and i~=index then
return nil
end
end
end