startScript re-entrancy has exceeded 3?

Morning guys, as you can see in the title i got this error while executing my local script for my loading screen, here you can see the output: output
hh

When i go to the line that is causing the error i have this:

lol

Also, as you can see in the output, it prints 3 times the prints methods, and also my TweenPosition doesnt work, here i leave my script.

game.ReplicatedFirst:RemoveDefaultLoadingScreen()
local contentProvider = game:GetService("ContentProvider")
local playerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
playerGui:SetTopbarTransparency(0)
local GUI = script.Parent:Clone()

GUI.Parent = playerGui
local loading_text = script.Parent.Background.TextLabel
print("going in")

local loadables = {
	
	game.Workspace:WaitForChild("City Street 3-Way Intersection"),
	game.Workspace:WaitForChild("ExplodingBarrel"),
	game.Workspace:WaitForChild("City Street Corner"),
	game.Workspace:WaitForChild("Observation Tower") 
	
}

local amount_loaded = 0

print("at one step of the for loop.")

for i, v in ipairs(loadables) do 
	contentProvider:PreloadAsync({v})
	amount_loaded += 1
	loading_text.Text = i.."/"..#loadables
end


if game:IsLoaded() then
	
	script.Parent.Background:TweenPosition(UDim2.new(0,0,10,0), "InOut", "Sine", 10, false)
	wait(10)
	script.Parent:Destroy()
	print("game has loaded")

end

Thanks in advance!!!

6 Likes

Basically, what’s happening is you’re cloning script.Parent which means that the script is also being cloned. This new, cloned, script, is also cloning script.Parent and you have yourself an infinite, gamebreaking loop.

Luckily Roblox catches these errors before you get an infinite loop which will crash the game, and it returns the error that your starting the script too many times (limit of 3).

Hope this helps,
-Tom :slight_smile:

29 Likes

is there any way around this error, like disabling it or pcalls? also sorry for like 3 month later comment…

You can’t escape from it, the only thing you can do is either destroy the clone’s script or put another LocalScript in it with Disable true and put Disable false when cloned

2 Likes

You can get around it by only cloning the GUI if it doesn’t already exist in PlayerGui.
In the case of the original poster, he only uses the GUI variable in handling the clone, so we don’t need to make sure that the variable exists. Obviously, depending on your secript, you may need to handle it differently.

if script.Parent.Parent ~= playerGui then
    local GUI = script.Parent:Clone()
    GUI.Parent = playerGui
end

This is a follow up to the orginal question, and it is directly related to the error at hand. Don’t worry about reviving this, it’s better to keep all of the identical stuff in one thread so people can find it easier, especially by just searching the error.

2 Likes

so like when I clone a script I get rid of the one that cloned it, or clone a script disabled then turn it false? could I do the second one in the same script?

The first one is you clone the object and then
Clone.Script_Path:Destroy()

And at the second one, there will be 2 scripts. only the first one Enabled, and after cloning the first one you need to unable and the second one(It should be the one with NO Object:Clone() in it) will be Disable.false It is 3 AM so please message me if anything I said may be confussing

1 Like