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

How to start function when certain player leaving?

I have player and if he leaving I want start a function something like

Players.PlayerRemoving:Connect(function()

end)

but with certain player

2 comments

0

is this certain player just someone on a specific team? or is it like an admin or something that should only work for him

0

You can thing it's randomly picked player by game.Players:GetPlayers [math.random(1, #game.Players:GetPlayers())

2 answers

✓ Accepted answer

If I'm understanding correctly, this might work

local plrs = game.Players:GetPlayers()
local plr = plrs[math.random(1, #plrs)]
game.Players.PlayerRemoving:Connect(function(player)
	if player.Name == plr.Name then
		
	end
end)

4 comments

0

Sorry, don't work. It making bugs in my script.

0

Okay, let me see if I can modify my script so it works

0

If I'm understanding you correctly, then my edited code might work

0

I fixed it by bool "check" now it's not making bugs. Thanks you.

Just check for their username using an if statement.

local Players = game:GetService("Players")

Players.PlayerRemoving:Connect(function(player)
	if player.Name == usernameWanted then
		--Execute the following code
	end
end)

Hope this helped!

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