I’ve been trying to make a script that checks if a player is already in a table, and if they are then they won’t be added. I tried to use table.find. Out of all the print functions only the first 2 print (print"Inserted 1 player, print"Hello" are the only ones that work)
while true do
if #plrs == 2 then --If there are already 2 people in the table then move on to the next part of the script
break
else--otherwise keep running this code until 2 people are in the table
script.Parent.Touched:Connect(function(hit)-- When the part is hit
local player = hit.Parent
if player then
if #plrs == 0 then-- if no players are in the table yet
print("Inserted 1 player")
table.insert(plrs,player)--Insert the player into the table
game.Workspace:WaitForChild(player.Name).Head.BillboardGui.Enabled = true --Enables the player's billboardgui
for i, player in pairs(plrs) do--Loops through the table
print("Hello")
if not table.find(plrs, player) then--if player is not already in the table..
print("player not in table")
table.insert(plrs,player) --.. insert them into the table
print("another playe inserted")
print(#plrs)
game.Workspace:WaitForChild(player.Name).Head.BillboardGui.Enabled = true--enables the gui
end
end
end
end
end)
end
wait()
end