So I'm making a game (duh) and I want it so if your on a team, then you will be spit onto one of four spawn points.
Here's the script:
KnightSpawnPoint = math.random(1,4) if game.Players.LocalPlayer.TeamColor == "Really Red" and KnightSpawnPoint == 1 then game.Players.LocalPlayer.Character.Head.CFrame = CFrame.new(447, 105.225, 299.22) elseif game.Players.LocalPlayer.TeamColor == "Really Red" and KnightSpawnPoint == 2 then game.Players.LocalPlayer.Character.Head.CFrame = CFrame.new(312.7, 105.225, 303.22) elseif game.Players.LocalPlayer.TeamColor == "Really Red" and KnightSpawnPoint == 3 then game.Players.LocalPlayer.Character.Head.CFrame = CFrame.new(315.7, 108.713, 432.77) elseif game.Players.LocalPlayer.TeamColor == "Really Red" and KnightSpawnPoint == 4 then game.Players.LocalPlayer.Character.Head.CFrame = CFrame.new(446.775, 108.713, 432.77) end
Now when I do this I get this error:
13:56:20.867 - Workspace.Script:2: attempt to index field 'LocalPlayer' (a nil value)
Can you please help me with this problem, much appreciated.
Please note I did not test some things I said, just saying what I think and know. So sorry if I end up saying something inaccurate.
As what kingdom5 said, server scripts can’t use LocalPlayer. I think it’s possible to move the localplayer’s position in a localscript though, so just change the script into a localscript to make things easier for you.
I also prefer you use MoveTo() instead of changing the CFrame of the head as I think changing the CFrame of the head will kill the player, while MoveTo() changes the position of the whole model.
Hoped this helped!