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:

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)
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.

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.

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