Unless this isn’t related. Though some people here still misunderstood how RunContext is expected to work.
The last few posts have run off of the actual bug. As I’ve already said, this happens for LocalScripts and Scripts with a RunContext of Client. This shouldn’t happen. Setting it to Legacy or Server causes it to run on the server where it doesn’t happen.
LocalScript
Runs twice when placed in StarterCharacterScripts. Not expected behaviour.
Script with RunContext set to Enum.RunContext.Client
Same behaviour as LocalScript; runs twice when parented to StarterCharacterScripts. Expected behaviour for that script type.
Script with RunContext set to Enum.RunContext.Legacy or Enum.RunContext.Server
Script runs once, but on the server. Expected behaviour.
In short - no matter the script setup, client scripts run twice when parented to StarterCharacterScripts (though they run under the character). It does not happen when they are moved to the character after a set interval from another location, which provides a workaround, but this is still incredibly annoying.
I seem to be unable to replicate this bug. You sure this isn’t a confusion between LocalScript
and Script
with RunContext
set on Client
? Their icons look similar, check their properties again.
Here are my findings:
Explorer hierarchy:
Output:
it doesn’t matter if it’s a LocalScript or a Script with RunContext set to client. As I’ve already said, it happens for both.
The image shows one LocalScript and one Script with Client RunContext.
Each script is one script with the line print("Hello world!")
line in it. Although the RunContext one printed 3 times here…
It’s expected behaviour for the RunContext script but not the LocalScript.
That still doesn’t explain why I cannot replicate this bug. I tried putting a simple LocalScript
and it only executed once. Maybe there’s more than meets the eye to your implementations?
Yeah, it’s inconsistent across places. I don’t know why. Other posts like this one i know that topic talks about gui and it’s not the exact same issue, but it also shows inconsistency and this bug report was linked to it.
and a few others also talk about inconsistency between places (i couldnt find them but i read about it).
The only pattern I can really think of/guess at is places with assets that are replicated at girst, like a loading screen in ReplicatedFirst, which could be causing the script to be run, delayed and not registered, and then run again, for some reason…
edit: that might also explain the slight delay between the first and second running of the script
Back when I was learning Lua and Roblox Studio I remember this happen to me. It’s not an engine bug and you can fix it yourself.
Have you tried adding some code to ensure the script or object is in the right parent of the game before running? In this case if it’s in StarterCharacterScripts then don’t run as that is just it’s starting location before it is reparented to the player character
Well, it is a bug, and what you’ve just suggested is a workaround. While a check like that would wait until it’s correctly parented, the script itself isn’t running parented to StarterCharacterScripts. I came up with a couple of other workarounds which I am using for now, but I’d like this to get fixed…
in this image, both of the messages have the output from the same script ancestry - workspace.12345koip.Movement
. If one was running when it was parented to StarterCharacterScripts, it would show that - I checked this by hovering over the messages to show the ancestry.
Thats might be showing that it’s under the same script name. What is best to do as a quick debug is to have it print where the script it’s located/parented to in the game. From there I may be able to tell you a work around
I appreciate the help, but I’ve already got a temporary workaround in place until this is fixed.
When I was taking this image earlier for @OniiSamaUwU:
this message showed twice with the same script ancestry, so I don’t think it’s that.
Okay. It’s an odd issue since it’s technically working as it should but just not as intended and I can’t think of any other way I fixed it other then checking where it is. As long as you’ve found a work around then thats good
Scripts in StarterCharacterScripts fires every time when character is reset. Are you sure you not respawning character another time after running the game?
Nope, it’s whenever I join the game. I don’t have anything that loads the character, and it happens for both LocalScripts and Scripts with RunContext of Client. I only use the LocalScripts, though.
Yes, I explain on this post that I belive it’s a bug because of its strange behavior and difficult to replicate.
As I said in my post, it happens in Place A but do not in Place B.
(My post isn’t acctually about GUIs, I just said that I noticed this problem while working in GUIs because the button click was being detected twice.)
I want to repeat that a Script
with it’s RunContext
set to Client
inside StarterCharacterScripts
is expected to run twice - this itself is not a bug. Do not get this confused.
For the final test, I would try running this LocalScript
inside StarterPlayerScripts
and see if this is outputting twice, assuming this container isn’t bugged for you as well. I would also like to ask if this behavior is happening upon resetting as well, or if it’s just upon joining:
--!strict
local Players = game:GetService("Players")
local LocalPlayer: Player = Players.LocalPlayer
local function onCharacterAdded(character: Model): ()
print("Character added")
while character:IsDescendantOf(workspace) == false do
character.AncestryChanged:Wait()
end
print("Character in workspace")
end
if LocalPlayer.Character ~= nil then
task.defer(onCharacterAdded, LocalPlayer.Character)
end
LocalPlayer.CharacterAdded:Connect(onCharacterAdded)
Thought so, I’ve corrected it in the title and main post. Thanks.
LocalScripts in StarterPlayerScripts don’t run twice, but the LocalScripts in StarterCharacterScripts run twice on join and on character reset.
Yeah, seems like a bug at this point assuming no other behavior is interfering. Can you send a screenshot of the script I provided output in the console?
well theres a bit of other output in the way which i wont send but here’s the results:
unsurprisingly both statements print twice when the script was parented to StarterCharacterScripts. They printed once when parented to StarterPlayerScripts.
The added statement printed before the other statement by about ~0.002 seconds, which suggests it’s running once under the character when the character has a nil
parent, but a recent update made it so LocalScripts can’t run as a descendant of nil
… odd.
Exactly the same is happening for me. Just to clarify, on some places (games) this happens, in others not. (This is the strange behavior that make me feel it is a bug)
yeah, same here. I find it happens more on places with assets that are loaded on join, if those assets are large enough, for example a loading screen. I’m unable to repro it on smaller places. The script runs ~0.02 seconds again after running the first time.