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

Teleportation does not work when you respawn?

Asked by
Ilitka 0
5 years ago
game.Players.PlayerAdded:Connect(function(pl)
    pl.CharacterAdded:Connect(function(char)
        local pos = CFrame.new(22, 10, 0)
        char:SetPrimaryPartCFrame(pos)
    end)
end)

This code does not teleport code, but if you add wait (1), it works. How to do without wait?

0
The reason this doesn't work is because you can't have nested events like that SteamG00B 1633 — 5y
0
I'll write up an answer with how you should have done it, eventhough you already answered it yourself SteamG00B 1633 — 5y

3 answers

Log in to vote
0
Answered by 5 years ago
game.Players.PlayerAdded:Connect(function(pl)
    pl.CharacterAdded:Connect(function(char)
local torso = char:WaitForChild("Torso") or char:WaitForChild("UpperTorso")
        local pos = CFrame.new(22, 10, 0)
        torso.CFrame = pos
    end)
end)
0
I don't know why, but your code doesn't work for me. I'm not teleporting. :( Ilitka 0 — 5y
0
hm maumaumaumaumaumua 628 — 5y
Ad
Log in to vote
0
Answered by
Ilitka 0
5 years ago

I found the only solution which works is to make a Local Script in StarterCharacterScripts with code:

local char = script.Parent

local pos = CFrame.new(22, 10, 0)
char:SetPrimaryPartCFrame(pos)
Log in to vote
0
Answered by
SteamG00B 1633 Moderation Voter
5 years ago

You should replace the inner event with a WaitForChild like this:

game.Players.PlayerAdded:Connect(function(pl)
    local char = pl:WaitForChild("Character")
    local pos = CFrame.new(22, 10, 0)
    char:SetPrimaryPartCFrame(pos)
end)

Answer this question