Doesn't check the players character(BindToClose)

game:BindToClose(function()
	print(0)
	for _,player in pairs(game.Players:GetPlayers()) do
		print(1)
		if player.Character.Name == "Tiger1" then
			print(2)
			game.ReplicatedStorage.Saves.Tiger:Clone().Parent = workspace
		end
	end
end)

It only prints 0!

2 Likes

It is possible the Player is removed before the game closes.

2 Likes
game.Players.PlayerRemoving:Connect(function(player)
	print("0")
	player.CharacterRemoving:Connect(function(character)
		print(1)
		if character.Name == "Tiger1" then
			print(2)
			game.ReplicatedStorage.Saves.Tiger:Clone().Parent = workspace
		end
	end)
end)

Same with this one!

1 Like

Check my other script,please, it has the same problem!

1 Like

If the PlayerRemoving event is fired, there is no need to check if the Player’s Character is being removed, because the character doesn’t matter if the player leaves the game.

3 Likes

But I want to check if the character has the name Tiger1 then do that and that!

1 Like

Do you rename the Character to something other than the Player’s name? If not, you might as well just use player.Name

3 Likes

So I am morphing the player and the name of the morph(character name) is tiger1 when changing to the tiger!

1 Like

That wouldn’t work, unfortunately!

2 Likes

Do you want it to only clone the thing when the player leaves, or do you also want it to run if the Player dies? If you just care about when the Character disappears, you can use this code:

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterRemoving:Connect(function(Char)
		
	end)
end)
1 Like

Clone it when the player leaves and then when the character is being removed like you scripted the script but I want to check if the character name is tiger 1 then I want to copy it into the workspace!

Just insert your code snippet into it then

1 Like

I have a question about this code here. Why would you want to clone parts into workspace when the game is about to close anyways?

Because I am making a piggy like game and I want to insert the bot tiger when the player tiger lefts!

1 Like
game.Players.PlayerRemoving:Connect(function(player)
	print("0")
	player.CharacterRemoving:Connect(function(character)
		print(1)
		if character.Name == "Tiger1" then
			print(2)
			game.ReplicatedStorage.Saves.Tiger:Clone().Parent = workspace
		end
	end)
end)

that keeps printing 0 only :frowning:

Yeah but BindToClose runs when the entire server is about to close. It means no player will be in the game anymore.

1 Like

yeah now look at my new script it keeps printing 0 nothing else!

It should be PlayerAdded, not PlayerRemoving

1 Like

but playeradded checks if the player has joined the game not left?

1 Like

Yeah, but you can’t bind the CharacterRemoving signal when the Player is leaving.