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

PlayerLeft event isn't working.. help?

Hey guys I was scripting and I bumped with the following problem...

--//If Player Left do..

local player = game.Players.LocalPlayer local playermoney = player.leaderstats.Money local owner = script.Parent.Owner local playername = player.Name local timeleft = script.Parent.TimeLeft local isbeingused = script.Parent.IsBeingUsed

game.Players.ChildRemoved:connect(function(player)

	if player.Name == owner.Value then

	owner.Value = ""

	timeleft.Value = 0

	isbeingused.Value = false

------------//-------------- end

This is basicly a script that changes Values if a CERTAIN player left the game.. Similar to a tycoon if the player left then the tycoon would reset but. This is not working. Maybe it's because the server can't read the name of the player that left because he DID left? Help ples ;-;

2 comments

0

use game.Players.PlayerRemoving:Connect(function(player) instead of ChildRemoved

0

I'll try. Thanks!

1 answer

✓ Accepted answer

I'm not quite sure what you're going for in the code, however, I can show you the answer to your dilemma.

Instead of trying to track ChildRemoved and ChildAdded for the Players service, just use Roblox's already premade events!

PlayerService=game:GetService("Players")

PlayerService.PlayerAdded:Connect(function(player)
	print(player.Name)
end)

PlayerService.PlayerRemoving:Connect(function(player)
	print(player.Name)
end)

Extra reading here.

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