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

How would I add for when a player leaves it also removes them?

So when a player leaves it breaks the round script. My game is round based and is based on who survives the longest but when a player leaves it breaks the game and makes them win. I know the issue is its not counting the player as removed when they leave so I cant figure out how to remove them once the player leaves heres my script

game:GetService('Players').PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		character:WaitForChild('Humanoid').Died:connect(function()
			local Update = {}
			for i, v in ipairs(_G.gameplayers)  do
				if v ~= player.Name then 
					table.insert(Update,1,v)
				end
				_G.gameplayers = Update
	        end
		end)
	end)
end)

2 answers

Remove the player that died from the table of players alive

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)

2 comments

0

Didn't work.

0

Then that code is not the origin of the issue, it must be in your other code that declares the winners

Try adding this code in somewhere:

player:kick()

That might work :3

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