Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does Changed work in Studio but not online?

So I have a Part that when it is Touched it Clones a Folder with a LocalScript in it into the Player's PlayerGui. To make the function in the LocalScript fire when it is copied, I had an event listener wait for its parent to be changed.

An equivelent example:

function PrintHello()
print("Hello")
end

script.Changed:connect(PrintHello)
--note that in my actual script it is actually script.Parent.Changed since the LocalScript is in a folder. Also, my function does more than print.

This worked fine when I tested it in Studio, but when I started a server the function for some reason does not fire (the folder is cloned in fine, though.)

Does anyone know why this is?

2 comments

0

From how I'm looking at the function; It does not have an 'end' to end the chunk.

0

Sorry, fixed. My real script does end too.

2 answers

✓ Accepted answer

I just tested the script you provided for myself and it worked fine for me.

I recommend throwing some extra 'print' commands throughout the script to see exactly what does run, what the values of various things are, etc. Sometimes things aren't fully loaded in Online mode and so the values aren't what you expect.

I find it odd that the script.Changed fires at all (though it definitely did when I was testing); it seems that the script gets run after its .Parent property changes but before the .Changed event fires. If your script waits for anything, it will miss the .Changed event.

Since LocalScripts don't run if they're in ReplicatedStorage (and most of the other locations too; the wiki explains exactly where it can run), if your localscript is in there, just assume that it's ready to go the moment the script starts running.

9 comments

0

Interesting. I created a new game and tried my basic example, but I got the same problem when I tried testing it in server mode. Are you sure you didn't do your test in Studio mode?

0

I'm unsure if I tested in in Server mode, so I did it again and it still worked. I had a server script in a Part copy a LocalScript from ReplicatedStorage into the player's PlayerGui and everything printed as expected.

0

Hm, it looks like the only difference between your test and my test is that I did not use ReplicatedStorage. I quickly recorded a video of my test example. Compare it to yours: https://www.youtube.com/watch?v=zRDPhCCgnpQ&feature=youtu.be

0

I duplicated your test environment but added more print statements. The localscript runs, but it doesn't get its ".Changed" event called.

0

How does it fire if the event that fires is isn't calling?

0

The print statement in the .Changed function doesn't fire, but the rest of the localscript runs fine without it. So, instead of doing "script.Changed:connect(DoSomething)" (if DoSomething is your function), just use "DoSomething()".

0

Ohhh, like as the first line? Will that work?

0

Yes.

0

Well I am so dumb because I forgot you can simply call a function to make it run first thing in the script! (I was for some reason thinking I needed to call it with an event...) Thanks so much this worked!

I'm not exactly sure what exactly what you're asking, but if you are looking for the ancestry of the object firing, use .AncestryChanged

function PrintHello()
print("Hello")
end

script.AncestryChanged:connect(PrintHello)
--note that in my actual script it is actually script.Parent.Changed since the LocalScript is in a folder. Also, my function does more than print.

2 comments

0

AncestryChanged will do the same thing that Changed will. What I am asking is why that above piece of script works in Studio Testing but not in an actual server.

0

Well I apologize, but your question wasn't clear. Are you checking the local console for the function's output? Is filtering enabled?

This discussion is preserved as it was. New answers, comments, and votes are closed.