Local Script Disappears For Some Reason

I have a script,

	for _,v in ipairs(game.Players:GetPlayers()) do
		print('yay!')
		local CameraAttachment = NEXUZ_STUFF_FOLDER.Cutscene.CameraSet:Clone()
		
		CameraAttachment.Parent = v.Backpack
		print(CameraAttachment.Parent.Name)
		CameraAttachment.CameraPart.Value = Nexuz.CameraPart.Part
		print(CameraAttachment.CameraPart.Value.Name)
	end	

(THIS IS NOT THE FULL SCRIPT! ITS THE LINE IM CONCERNED ABOUT)
So, the LocalScript does get parented to the player’s backpack.
But it destroys itself shortly after, which makes the localscript disable itself.

Is there a solution to this? Or I’m parenting it wrong?
If you have any theories, tell me.

I personally would not put it in the backpack. I would put it in StarterPlayerScripts.
Parenting it to the backpack is probably what is causing your issue, but I might be wrong.
I’m pretty sure the backpack deletes things that are not tools, but I’m not sure. I’ve never put anything but tools in the backpack.

Well, when I do that. It says PlayerScripts is not a valid member of Player? But I’ll try this again.

Well, what I mean is when you clone the CameraAttachment, I would not parent it to the backpack. I would put it into the player’s PlayerGui personally. I’m assuming CameraAttachment is the LocalScript you are referring to, but correct me if I’m wrong.

Parenting a LocalScript to StarterPack and or Backpack is ok, there is nothing wrong with that as Roblox allows you to add them there anyway:

Are you sure you didnt accidentally Disable Archivable? on the Script?

1 Like

image
Nope, it is not disabled.

I just want to let you know that the backpack is recreated when the player dies.
image

The character doesn’t die though

Pretty sure, your code will only run inside a tool, local scripts do not run automatically in the backpack unless a tool is equipped/used or interacted with. Like other players suggested, you can put the script into the PlayerScripts folder or into any of the other categories below,
image