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

Teleportation does not work when you respawn?

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?

2 comments

0

The reason this doesn't work is because you can't have nested events like that

0

I'll write up an answer with how you should have done it, eventhough you already answered it yourself

3 answers

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)

2 comments

0

I don't know why, but your code doesn't work for me. I'm not teleporting. :(

0

hm

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)

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)

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