Why is my :Clone() being randomly deleted?

Hello there. Recently I encountered an issue with my code. A little bit information - I am trying to write a server sided script, that when a player shoots their weapon, creates copies of the two parts of the tool that hold all of the ParticleEmitters, parents them to Workspace, and enables/disables them.

The issue I encountered, is that if I unequip the tool, with the original parts, the :Clone()'d parts are deleted from Workspace. Does anyone have any idea on how I can fix this?

	-- More logic above
	local ShootPart = Tool.ShootPart:Clone()
	local SideBlast = Tool.SideBlast:Clone()
	ShootPart.Parent = workspace
	SideBlast.Parent = workspace
	-- Redacted part that enables and disables ParticleEmitters

Out of curiosity, I added the following code to the bottom, and got an error.

	wait(5)
	-- I would unequip before the wait(5) is done waiting
	print(ShootPart.Parent.Name)

Error:

Players.MentallyDisturbedNub.Backpack.Musket.Server:288: attempt to index nil with 'Name'

I’ve tried everything I can think of to fix this, and have been stuck on this for over 2 hours. Could this be a ROBLOX bug?

At the bottom it gives u that error cause ShootPart has been probably deleted, make sure the original part is anchored, this could be the problem because any part that falls off the map gets automatically deleted by the game.

1 Like

Thank you so much, I completely forgot about that!

The parts were Motor6D’ed/Welded to the musket, so I had Anchored turned off.

I guess I just had a really big brain fart :expressionless:

1 Like