Attempt to index nil with PrimaryPart

Why is this happening? What can i do to fix this?

local rp = game:GetService("ReplicatedStorage")
local Event = rp:WaitForChild("CharacterClone")

Event.OnServerEvent:Connect(function(player, isActive)
	if isActive then
		local Character = player.Character
	     Character.Archivable = true
		local NewCharacter = Character:Clone()
		
		NewCharacter.PrimaryPart.Position = Character.PrimaryPart.Position -- Error here
		
	end
	
end)
1 Like

Maybe try

local Character = Player.Character or Player.CharacterAdded:Wait()

and you do have to make it archivable like above

Try parenting it to the workspace instead of just cloning it & setting its position

local rp = game:GetService("ReplicatedStorage")
local Event = rp:WaitForChild("CharacterClone")

Event.OnServerEvent:Connect(function(player, isActive)
	if isActive then
		local Character = player.Character
	     Character.Archivable = true
		local NewCharacter = Character:Clone()
		NewCharacter.Parent = workspace
		NewCharacter.PrimaryPart.Position = Character.PrimaryPart.Position -- Error here
	end
end)
2 Likes

I turned it on but that still did nothing

That also did nothing

I suppose the reason why this error occurs is that the PrimaryPart is not visible just yet, since you’re only cloning & assuming that there is a valid PrimaryPart property inside which is resulting as a nil value

This is maybe the only evidence I could find on the Dev Hub:

1 Like