LocalScript runs twice (in one place, but not in another)

I was working on a GUI LocalScript and noticed that the function called when you click a certain button was executing twice.

After investigating, I noted that the code was running twice, one time in ‘Client’ and another in ‘Studio’.

This is strange, because in one place, it runs only once (and is the same script parented to the same location, StarterGui)

This is the content of the LocalScript, tested in 2 different places.

print("Hello world!", game.PlaceId) -- note this will print the place ID

Place A: (runs once, as expected)
image

Place B: (runs twice)

I saw in this post that you can check where the script is located before executing it (like checking if script.Parent.Name=="StarterCharacterScripts").

But the problem is, WHY the behavior is different in these places? What is happening? Is it a bug?

Why in place A I don’t need to check the script’s parent before executing and in place B I do?

is it runcontext client or a normal localscript?

It is a normal LocalScript in both places.

Could you print the parent of each script? My guess is that it may have something to do with replication from StarterGui.

Sure. It has a really strange behavior. When I print the Parent, it shows ‘Client’ on both lines:

print("Hello world! Parent:", script.Parent.Name, "Place ID: ", game.PlaceId)

However, when I try to print just the “Hello World” and the place ID, it shows ‘Studio’ and ‘Client’:

print("Hello world! Place ID: ", game.PlaceId)

And again, on the another place, it runs only once (as expected)


(note the different place IDs)

While you’re in the game, could you click “LocalScript:1” for each output? It should bring you to the script that printed each output. I’m not sure if this works as I’m away from my computer right now but it’s worth a try.

Or maybe click the text itself, again I’m not too sure which one works.

Yes, acctually I already tested this. Again a strange behavior (at least for me).

The second line takes me to the correct path, the original script (as expected):

But when I hover the mouse on the first line, it says “Font not available” and nothing happens when click:

(and this time, for some reason, it shows ‘Client’ on both, before it was showing ‘Studio’ on the first and ‘Client’ on the anoter, as you can see on the previours replies.)

Edit: Just tested it, I really think this might be a bug. Sometimes it shows ‘Client’, ‘Client’, and sometimes ‘Studio’, ‘Client’.

Edit2: I just tested and this only happens in some places (in some it runs once and in others it runs twice). I still couldn’t figure out why.

It looks like there’s a Bug Report for this:

1 Like

i had this problem before, just dont use the Script and set RunContext to Client. Use Localscript instead because RunContext-Client is most likely the problematic one

This isn’t truly a bug. Do not put a regular script with the context on Client in script containers, as they do not follow the rules that a LocalScript does. It will execute in the container, and then a clone of it will be made over to the player or character, and then execute it twice.

Additionally, for the bug report sent above, I think someone has a misconception on which are LocalScripts and Scripts set on the context on Client, since their icons are easily confused with each other.

I’m not using normal Scripts. I’m using LocalScripts.

I belive it’s a bug because the same LocalScript with the same code has different results on different places.

And sometimes it prints ‘Client’, ‘Client and sometimes ‘Studio’, ‘Client’.