Code Works in Studio, but not In-game

Hello there!
So, I’m trying to make a unioned box containing 6 parts, and I have a script where when the box is clicked, it fades out. It works perfectly in Studio, but not in-game. I need help!

local Present = script.Parent.Parent

	for i = 0, 10 do
		Present.Union.Transparency = Present.Union.Transparency + 0.1
	Present.Union.CanCollide = false

Present is a model with a union inside of it.

Is there any errors, maybe a wait for child is needed.

No errors. It stopped working in studio now, too. Where would I add in the wait for child?

try adding prints throughout the script and test it in-game to see which part of the script is working and which isnt so its easier to fix.

I would add in :WaitForChild to the local Present = script.Parent, right? Also, I found out that it works when it is in workspace, but I’m trying ot get it to be parented to workspace from server storage when I click a button, and that’s when it breaks.

i dont think you need the waitforchild for local Present = script.Parent.Parent but try putting the object in replicated storage instead and cloning it from there instead of sever storage? i dont use server storage since it sometimes bugs out when i try cloning from there.

I tried moving it to Replicated Storage, it didn’t work. I added the wait for child parts, and it still didn’t work.

I cant debug this as you haven’t provided enough information on the context of your script

Its worth noting that a Server Script, will only run in the following contexts

  • A descendant of Workspace
  • A descendant of ServerScriptService
  • A descendant of Player*
    *This behaviour is a bit wacky and is unreliable, it’s best practise outside of tools to use localscripts when dealing with players

does the script still print anything when you clone it and click it? and is it still giving no errors?

No errors. It works just fine in workspace, but not when I clone it from anywhere.

can you add your script thats used to clone it?

Okay I want to suggest something, I’m not saying you should do this but, if you’re using this how I think you’re using this, it will get unmaintable VERY quickly.

Consider looking into CollectionService

The tags are saved to files when you add them in Edit mode.