Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Teleport to other game when died doesn't works?

Asked by 4 years ago
Edited 4 years ago

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

ServerScript:

01local GameId = 4950975351
02 
03game.Players.PlayerAdded:Connect(function(plr)
04    plr.CharacterAdded:Connect(function(chr)
05        local humanoid = chr:WaitForChild("Humanoid")
06    if humanoid.Died then
07        game:GetService('TeleportService'):Teleport(GameId, plr)
08        end
09        end)
10end)
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 Sonickirbystar 0 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

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.

1local gameId = 4950975351
2 
3game.Players.PlayerAdded:Connect(function(plr)
4    plr.CharacterAdded:Connect(function(char)
5        char:WaitForChild("Humanoid").Died:Connect(function()
6            game:GetService('TeleportService'):Teleport(GameId, plr)
7        end)
8    end)
9end)

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.

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. Ziffixture 6913 — 4y
0
Thanks, it worked. benjinanas 50 — 4y
Ad

Answer this question