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

Teleport to other game when died doesn't works?

Instead of teleporting me when I die, it teleports me as soon as I spawn n the game

ServerScript:

local GameId = 4950975351

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(chr)
		local humanoid = chr:WaitForChild("Humanoid")
	if humanoid.Died then
		game:GetService('TeleportService'):Teleport(GameId, plr)
		end
		end)
end)

1 comment

0

Something with when the player loads the health goes from 0 to 100 SUPER quickly. I messed around with something like this before so I just put a delay in it

1 answer

✓ Accepted answer

humanoid.Died is a function for whenever humanoids die. You cannot call it in an if statement. Instead, you're going to want to make a function for when the humanoid dies.

local gameId = 4950975351

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char:WaitForChild("Humanoid").Died:Connect(function()
			game:GetService('TeleportService'):Teleport(GameId, plr)
		end)
	end)
end)

If this fails, then remove the PlayerAdded and CharacterAdded functions and insert the rest of the code into a localscript in StarterPlayerScripts. Add local plr = game.Players.LocalPlayer below local gameId = 4950975351 instead.

2 comments

0

Died isn't a function, it's and RBXScriptSignal (an event). You tie a callback (invoked function) to it upon the signal firing; in this case is the process that occurs upon the death of the Player.

0

Thanks, it worked.

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