Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to remove the player from the table when he dies?

Asked by 4 years ago

I have been trying to remove the player from the table when the player dies it actually does work BUT it removes the other players from the table either.

Code:

game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function(playerdied)    
print(player.Name .. " has died!")
for i, player in pairs (game.Players:GetPlayers()) do
warn(player, 'has Been Removed From Table - Intro Or AFK.')
for i = 1, #queue1 do
if queue1[1] == player then
table.remove(queue1,i)
end
end
end
end)
end)
end)
0
line 8 replace queue1[1] with queue1[i] Optimalpokemon123 37 — 4y
0
Did not work it still removes the other player from the table Anton00k 2 — 4y

1 answer

Log in to vote
1
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago

A couple of things are wonky here. You are looping through each player in game.Players and each player your looping through is under the variable 'player'. This is fine, but take note that you're checking if queue1[1] == player on line8 (should be queue1[i]) and every player will eventually be player.

If your table contains the player instances in game.Players, keep looping through using this code, but make sure to change line 8 to queue1[i] and give the loop on line 5 a different name such as currentPlayer. It has the same name as the variable player on line 1 and the script can't tell them apart.

0
Thank you so much! I have been trying for 3 days now! BTW How do I mark the post as answered? Anton00k 2 — 4y
0
I'll figure it out in a sec... royaltoe 5144 — 4y
0
Not quite sure, but I'm glad you found your answer anyway. royaltoe 5144 — 4y
Ad

Answer this question