Script can't find player's HumanoidRootPart?

I have a local script checking for the player’s HumanoidRootPart and Character so it can set the spawn based on a certain value but this just pops up?

image

My script:

local plr = game.Players.LocalPlayer
local char = plr.Character

game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.All, false)

--first time playing?
if plr:WaitForChild('PlayerStats').SavePoint.Value == 0 then
	char.HumanoidRootPart.CFrame = workspace.StartSpawn.CFrame
end
1 Like
repeat wait() until game.Players.LocalPlayer -- Wait until the player is loaded

local plr = game.Players.LocalPlayer
local char = plr.Character

game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.All, false)

--first time playing?
if plr:WaitForChild('PlayerStats').SavePoint.Value == 0 then
	char.HumanoidRootPart.CFrame = workspace.StartSpawn.CFrame
end
3 Likes

thank you, THANK YOU so much!!

2 Likes

hi wait, i just tested it out in game and it still doesnt seem to work, same error but in studio its working just fine?

1 Like

Don’t forget to publish the game

1 Like

i did, but it seems to have fixed itself when i added a tiny wait.

1 Like

Only core scripts have to worry about the LocalPlayer being loaded. You don’t need to wait for LocalPlayer to exist. The problem is that the character wasn’t spawned in yet. The reason the error stopped with this solution is because of the wait() in the repeat loop. It runs before it checks the condition in the loop, so this is a band-aid fix, which will only work on fast computers. He should use this instead:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.