Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why does Changed work in Studio but not online?

Asked by
emite1000 335 Moderation Voter
9 years ago

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?

0
From how I'm looking at the function; It does not have an 'end' to end the chunk. TheeDeathCaster 2368 — 9y
0
Sorry, fixed. My real script does end too. emite1000 335 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago

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.

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? emite1000 335 — 9y
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. chess123mate 5873 — 9y
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 emite1000 335 — 9y
0
I duplicated your test environment but added more print statements. The localscript runs, but it doesn't get its ".Changed" event called. chess123mate 5873 — 9y
View all comments (5 more)
0
How does it fire if the event that fires is isn't calling? emite1000 335 — 9y
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()". chess123mate 5873 — 9y
0
Ohhh, like as the first line? Will that work? emite1000 335 — 9y
0
Yes. chess123mate 5873 — 9y
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! emite1000 335 — 9y
Ad
Log in to vote
-2
Answered by 9 years ago

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.
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. emite1000 335 — 9y
0
Well I apologize, but your question wasn't clear. Are you checking the local console for the function's output? Is filtering enabled? Verbero 0 — 9y

Answer this question