Attempt to index nil with 'CFrame' error

  1. What do you want to achieve? That it doesn’t return the error

  2. What is the issue? It gives an error

  3. What solutions have you tried so far? I’ve tried looking but I couldn’t find anything…

It doesn’t break the whole script but it’s annoying seeing that error for a reason that I don’t know

This is the part that gives the error This is not the whole script

	player.CharacterAdded:Connect(function(character)
		local Humanoid = character:WaitForChild("Humanoid")
		local HumanRoot = character:WaitForChild("HumanoidRootPart")
		wait()
		if HumanRoot and Humanoid then
			if Stage.Value ~= 0 then
				local StagePart = workspace.Checkpoints:FindFirstChild(Stage.Value)
				HumanRoot.CFrame = StagePart.CFrame + Vector3.new(0,1,0)    
			end 
		end 
	end)  
end)

Hope someone can help!

and an

if StagePart then

so:

	player.CharacterAdded:Connect(function(character)
		local Humanoid = character:WaitForChild("Humanoid")
		local HumanRoot = character:WaitForChild("HumanoidRootPart")
		wait()
		if HumanRoot and Humanoid then
			if Stage.Value ~= 0 then
				local StagePart = workspace.Checkpoints:FindFirstChild(Stage.Value)
				if StagePart then
					HumanRoot.CFrame = StagePart.CFrame + Vector3.new(0,1,0)    
				end
			end 
		end 
	end)  
end)
1 Like

Maybe try to turn the Stage Value into a string?
So it should look like this:

local StagePart = workspace.Checkpoints:FindFirstChild(tostring(Stage.Value))