Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I make it to where someone leaves it removes them from the game round?

So im having an issue where if a player leaves in the middle of a round it breaks it due to it not removing them when they leave. I already have the script that removes them when they die but I don't know how to make it remove them when a player leaves.

Can someone help?

game:GetService('Players').PlayerAdded:connect(function(player)
	
    player.CharacterAdded:connect(function(character)
        character:WaitForChild('Humanoid').Died:connect(function()
            for i, v in ipairs(_G.gameplayers)  do
                if v == player.Name then 
                    table.remove(_G.gameplayers, i)
                    break
                end
            end
        end)
    end)
end)

1 answer

✓ Accepted answer

Well, there is an event called PlayerRemoving, when player leaves the game. Here's a sample script, that might help you understand :

game.Players.PlayerAdded:Connect(function(player)
    print(player.. ' has joined!')
end)

game.Players.PlayerRemoving:Connect(function(plr)
    print(plr.. ' has left!')
end)

Also, make sure to have capital 'C' in Connect, lowercase 'c' is deprecated.

Lemme know if it helps!

This discussion is preserved as it was. New answers, comments, and votes are closed.