I am trying to make a tournament system. When the admin starts the tournament, players get a prompt where they choose if they want to participate.
Players are not removed from the “Players” table when they leave. I can’t find the issue with my code.
My current code (serverside, the issue is not on the client so that code will not be provided):
remChoose.OnServerEvent:Connect(function(plyr)
table.insert(Players, plyr)
remStart:FireClient(plr, #Players) -- sends updated player count to admin
end)
local removeplr = game.Players.PlayerRemoving:Connect(function(player) --SHOULD remove players from table when they leave but DOESNT
for i, v in pairs(Players) do
print(i)
print(v.Name)
if game.Players:FindFirstChild(v.Name) == nil then
table.remove(Players, i)
end
end
remStart:FireClient(plr, #Players) --send updated player count to admin
end)
You can’t call a function inside a variable, use this instead.
remChoose.OnServerEvent:Connect(function(plyr)
table.insert(Players, plyr)
remStart:FireClient(plr, #Players) -- sends updated player count to admin
end)
game.Playes.PlayerRemoving:Connect(function(player)
for i, v in pairs(Players) do
print(i) print(v.Name)
if game.Players:FindFirstChild(v.Name) == nil then
table.remove(Players, I)
end
end
end)
If that doesn’t work then let me try something else. ^