Attempt to index nil with 'WaitForChild' error making zero sense

The title explains it and here is my local script

local plr = game:GetService("Players").LocalPlayer
local mouseService = game:GetService("MouseService")
local plrMouse = plr:GetMouse()
local mousePos = plrMouse.Hit
local re = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("MouseFace")
local RunService = game:GetService("RunService")

RunService.RenderStepped:Connect(function()
	local Char = plr.Character
	local Root = Char:WaitForChild("HumanoidRootPart")
	
	local RootPos, MousePos = Root.Position, plrMouse.Hit.Position
	Root.CFrame = CFrame.new(RootPos, Vector3.new(MousePos.X, RootPos.Y, MousePos.Z))
end)

The function is running before the character has loaded.
Try printing Char after declaring it.
As the function is using the mouse could it be changed to run on a mouse event instead of runservice?
(Or the paths for re aren’t correct?)

how is this getrrting seen more then my new post ?

If the function is supposed to update the CFrame every frame regardless of whether the player moved their mouse on the screen, I wouldn’t recommend using a mouse event. Mouse.Hit can change even if the mouse stays at the same location on the screen. Instead, I’d suggest making the following change:

RunService.RenderStepped:Connect(function()
	local Char = plr.Character
	if char == nil then
		return
	end
	local Root = Char:FindFirstChild("HumanoidRootPart")
	if Root == nil then
		return
	end
	
	local RootPos, MousePos = Root.Position, plrMouse.Hit.Position
	Root.CFrame = CFrame.new(RootPos, Vector3.new(MousePos.X, RootPos.Y, MousePos.Z))
end)

Of course, if you need to do checks like this in many places in your code, it may be a good idea to write a separate module script function that can be used to check if the character exists and has everything it should have.

Good point, I keep forgetting that :slight_smile:

Instead of

local Char = plr.Character

Try

local Char = plr.Character or plr.CharacterAdded:Connect(Wait)