Like frosty said, LocalPlayer can only be used in a LocalScript. LocalScripts run on the client, aka you. A normal script has no idea who the client is. Use CharacterAdded to know when you can move the player. If you try moving them after they die, you're just going to teleport their dead body. CharacterAdded fires after your character loads from a death or otherwise.
local ws = game:GetService("Workspace")
local players = game:GetService("Players")
local spawn_pos = ws:WaitForChild("Stage1Spawn").Position + Vector3.new(0,1,0)
local function player_joined(player)
player.CharacterAdded:Connect(function(char)
local stage_num = player:findFirstChild("StageNum")
if stage_num and stage_num.Stage.Value == 1 then
char:MoveTo(spawn_pos)
end
end)
end
players.PlayerAdded:Connect(player_joined)
for i,v in pairs(players:GetPlayers()) do
player_joined(v)
end
3 comments
What script is this code in and where is it located.
its a regular script and in serverscriptservice
LocalPlayer can only be used in a Local script