Here's my script:
_G.addremovePlayers = function() for _,v in pairs(game.Players:GetChildren()) do table.insert(_G.playersLeft,v.Character.Name) end for i = 1,#_G.playersLeft do print(_G.playersLeft[i]) end end
I can't really seem to figure out how to remove someone's name from a table when they die.
Let me be more specific if you don't understand. 3 players join a game and when the round starts, their names are put in a table. {a, b, c}. Player b dies and I want b to be taken out of the table so it would be {a, c}.
if you put this in the StarterCharacterScripts, I believe it should work:
local humanoid = script.Parent:FindFirstChild("Humanoid") humanoid.Died:Connect(function() table.remove(_G.playersLeft,script.Parent.Name) end)
Hi.
I never actually experimented with this, soo.. Let's give it a go.
function participate() for _, Player in pairs(game.Players:GetPlayers()) do _G.playersLeft[Player.Name] = true v.Character:FindFirstChildOfClass("Humanoid").Died:connect(function() print(Player.Name.. ' Has died! Remaining players: '.. #_G.playersLeft) _G.playersLeft[Player.Name] = nil end) end end game:GetService('ReplicatedStorage').RemoteFunctions.addPlayers.OnServerInvoke = participate
If it errors, let me know.
One way to do it is to iterate through each value in that table, then get the name of the player who dies, and remove it if found.
Example: (Note you have to replace and change some stuff in the code below)
humanoid.Died:Connect(function() for i,v in pairs(_G.playersLeft) do if v.Name == PLAYERNAME then table.remove(_G.playersLeft, i) end end end