So i'm making a demo game, where whenever you join, it waits 5 seconds, then teleports you to 1 of 2 blocks. Then five seconds later, it does it again. This works in Studio, but not in the Game. Here is the script: (This is a SCRIPT [not local] in ServerScriptService)
while true do
local Tab = {CFrame.new(26, 0.5, -1); CFrame.new(26, 0.5, -33)}
local locationselected = Tab[math.random(1, #Tab)]
wait(.2)
game.Workspace:WaitForChild(game.Players.LocalPlayer.Name).Head.CFrame = locationselected
wait()
end
i tried adding a player added event:
game.Players.PlayerAdded:Connect(function(player)
while true do
local Tab = {CFrame.new(26, 0.5, -1); CFrame.new(26, 0.5, -33)}
local locationselected = Tab[math.random(1, #Tab)]
wait(.2)
game.Workspace:WaitForChild(game.Players.LocalPlayer.Name).Head.CFrame = locationselected
wait()
end
end)
but thats not working either. Any help?

3 comments
LocalPlayer is nil on the server.
oof. Is there any other way to reference the players name?
Answered