LocalScripts in StarterCharacterScripts are being run twice (not Scripts with RunContext set to Client)

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

1 Like

Scripts in StarterCharacterScripts fires every time when character is reset. Are you sure you not respawning character another time after running the game?

1 Like

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.)

1 Like

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.

1 Like

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?

1 Like

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 sscript runs ~0.02 seconds again after running the first time.

1 Like

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.

My server “Spawn” code

local players = game:GetService("Players")


players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char.Parent = nil
		task.wait()
		char.Parent = workspace
	end)
end)

Here is my result with just one line of print
image

image

image

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.

1 Like

Is it by any mean possible to show code in the CharacterAdded block?

idk, i mean theres a lot of characteradded connections i have but it’s only a RBXScriptSignal and it does not modify the character in any way.

I also mentioned this issue is inconsistent - I just tried to repro it and couldn’t. Sometimes it happens and sometimes not.

I see I just noticed that in the picture you send in other post (below here) have no Animate script which usually included by default so I just think at least there are script that handle delete and adding stuff to player’s character.

That was a bug from some of my other code. In one of my previous replies, I mentioned the character getting cloned and the LocalScripts instantly getting removed from it, then it getting put into a ViewportFrame. Well, I referenced my character there by mistake which caused that.

I took another look at that because I thought it could be causing issues and fixed that to reference the cloned character and then tested again to make sure.

The code at the top of the script:

print("this script is so freaking awesome!")
if not script:IsDescendantOf(workspace) then print("oi! this script not in the workspace!") script:Destroy() end
print("hmmhmhmhmmhm")

I got this output:


which shows the script got destroyed but is still running, this time with the “Studio” tag for source. It says “Source not available” when hovering, so it definitely got destroyed.

I think something is going on with viewport cloning?

Here is my viewport script and explorer

local plr = game:GetService("Players").LocalPlayer

local char = plr.Character or plr.CharacterAdded:Wait()

char.Archivable = true

local cloned = char:Clone()

char.Archivable = false
cloned.Parent = script.Parent.ViewportFrame.WorldModel

image

I got output exactly like your.
image

Have you tried delete local script in viewport before parent them?
like

local plr = game:GetService("Players").LocalPlayer

local char = plr.Character or plr.CharacterAdded:Wait()

char.Archivable = true

local cloned = char:Clone()

char.Archivable = false

--Delete script in cloned model for viewport
for _,v in cloned:GetChildren() do
	if v:IsA("LocalScript") then
		v:Destroy()
	end
end

--Set to world model
cloned.Parent = script.Parent.ViewportFrame.WorldModel

Here is my output after delete script in viewport
image

yep i did exactly that but each time i made it also print script:GetFullName() (this is with the viewport script disabled so the character is not cloned) so then for the messages that did have a source i opened them and clicked “Show in Explorer” and they all point to that one LocalScript under my character.