Attempt nil with HumanoidRootPart

Why is this happening?
it keeps saying

	for i, v in pairs(workspace.Items:GetChildren()) do
		if EquippedVal.Value == v.Name then
			local CharacterClone = v:Clone()
			print("Cloned")
			CharacterClone.Name = player.Name
			print(CharacterClone.Name)
			local cframe= player.Character.HumanoidRootPart.CFrame --This is where the problem is
			player.Character:Destroy()
			print("Destroyed")
			player.Character = CharacterClone
			print("Nearly")
			local root = CharacterClone:WaitForChild("HumanoidRootPart")
			local hum = CharacterClone:WaitForChild("Humanoid")
			wait()
			root.CFrame = cframe
			CharacterClone.Parent = game.Workspace
		end
	end
end

In your output it is showing that the character is added after your error. Attempt to index nil with ________ means in this case that your character doesn’t exist yet (character is nil).

Try moving this code into the portion of your script where it knows when the character is loaded in. I guess you can also wait until the character is not nil by checking before you do stuff with it.

1 Like

You should yield until the Character model is loaded, you’re referencing something that isn’t parented to the datamodel yet.

try using player.CharacterAdded

1 Like

Now it’s infinite yielding with this

local root = CharacterClone:WaitForChild("HumanoidRootPart")

How would i do this?

How would i do it with a custom character

Make sure that your custom character has a humanoid root part. Otherwise I don’t know what the issue would be here.