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

How do you teleport the local player in a local script?

This is my code but I don't know why it is not working

if game.Players.NumPlayers < 4 then

local spawns = game.workspace.Wait:WaitForChild('waiting'):GetChildren() for _, player in pairs(game.Players:GetPlayers()) do if player and #spawns > 0 then local head = player.Character:WaitForChild('Head') local allspawns = math.random(1, #spawns) local randomspawn = spawns[allspawns] if randomspawn and head then head.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0)) end end end end

1 comment

0

Please use a code block for your script.

1 answer

✓ Accepted answer

Note: Create a local script in StaterPack or StarterGui.

I've tried to base this of the code example you gave above.

local player = game.Players.LocalPlayer
local spawns = game.workspace.Wait:WaitForChild('waiting'):GetChildren()

local head = player.Character:WaitForChild('Head') 
local allspawns = math.random(1, #spawns) 
local randomspawn = spawns[allspawns] 

if randomspawn and head then head.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0, 2, 0)) 

   	end 
end 
 

1 comment

0

Let me know if you encounter and problems.

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