Script breakes when adding something

So i got another problem with the tree breaking system. I know i’m stupid, but i don’t know why the script breakes.
So basically the script breakes when i add a effect that spawns a log before the destroy happens.
But when i add it, i get a error in output saying “Attempt to index nil with position” on line 21, but when i delete the log part of the script it works completly fine. I don’t know why that happens.
Any help will be appreciated.

Anyways here’s my script

RemoteEvent2.OnServerEvent:Connect(function(player, breakable)
	local Log = game:GetService("ServerStorage").DroppedItems.Log:Clone()
	Log.Position = breakable.PrimaryPart.Position - Vector3.new(0, 3.5, 0)
	Log.Orientation = Vector3.new(math.random(0, 360))
	Log.Parent = workspace
	breakable:RemoveTag("Breakable")
	task.wait()
	breakable:Remove()
end)
1 Like

I am guessing you’re getting the error in the following line:

Log.Position = breakable.PrimaryPart.Position - Vector3.new(0, 3.5, 0)

Can you please print what breakable’s PrimaryPart is before doing that, it may be nil for some reason, also make sure that breakable is a Model.

1 Like

Seems like breakable is a model and its primary part isnt nil :frowning:

Use Log:SetPrimaryPartCFrame() instead then, that should let you set the position and orientation of the PrimaryPart of the Log.

1 Like