Player leaving event help!

image

So this my current script which if a player leaves in round it will remove them from the player inrounds folder. This should work but for some reason doesn’t and the game teleport just breaks which breaks the entire game.

Players in the InRounds folder are string values which are stored as the players name.

So what I want to happen is when the player leaves then it will get rid of them from the inround folder.

Any help will be appreciated!

Probably because you didn’t set it to game:GetService(‘Players’).LocalPlayer

edit: I tested it and it worked your script. So do what below said.

This script should be working but you might want to get rid of the WaitForChild because your player is most likely loaded in at that point.

2 Likes

@daslick

This is probably not the case because he already had a localplayer parameter in the function he connected to his PlayerRemoving event.

I see the parameter I would’ve thought it would be LocalPlayer for reasons

Right now in the if statement you are comparing “player.Name” (a string) to an instance “game.Workspace.MainFrame.InRound:WaitForChild(player.Name)”. This will always return false. Instead, compare player.Name to the name of the UIElement inside of “InRound”, or it’s text. Something that is a string that should be the name of the player.

1 Like

image

I got this error message when I tested out a player leaving?

image

This is because you put parenthesis around player.Name, which is used for calling a function. Instead use :FindFirstChild or brackets “[]” surrounding the string

@TheDCraft

In your if statement you should change (player.name) to [player.name] because you are looking for the instance called player.name

image

This is what I currently have it as. And I get an error say that the player is not a valid member of Folder

I think IsKid has the solution. But this is what I would do for the script. A bit different from yours but it should work better I believe.

local players = game:GetService("Players")

players.PlayerRemoving:Connect(function(player)
	local playerString = workspace.MainFrame.InRound:FindFirstChild(player.Name)
	if playerString then
		playerString:Destroy()
		print("Destroyed")
	else
		print("No StringValue named "..player.Name)
	end
end)

I’ll help if there’s any more issues

Edit: fixed format

1 Like

Thanks it did work! Also thanks to everyone that helped! :heart: