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.
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 onei 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
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.
I want to repeat that a Script with it’s RunContext set to Client inside StarterCharacterScriptsis 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)
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.
Hey there! I assume you have some kind of server script that on character spawn temporary set character parent to nil and then set back to workspace. I think that local script in player character run once when they spawn (They already in workspace in this time) then again when they re-parented to workspace.
Thanks for the suggestion, but I don’t have any code that modifies the character’s ancestry. It’s all done by Roblox scripts - the only related thing I use is the CharacterAdded event.