Script runs too many times

I have a loading screen script that clones a Gui with a script inside to PlayerGui, the Gui script is only supposed to run once but for some reason it either runs twice or three times.

Load script:

game.ReplicatedFirst:RemoveDefaultLoadingScreen()

local playerGui = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")

local LS = script.LoadScreen:Clone()

LS.Parent = playerGui

-- Load proccess --

if not game:IsLoaded() then

game.Loaded:Wait()

end

wait(3)

LS:Destroy()

local Main = script.Main:Clone()

Main.Parent = playerGui

script.Loaded.Value = true

Gui Script:

print(“Test”)

Results: Screenshot 2021-03-29 144628

I only want the Gui script to print Test once, any ideas what’s going on?

1 Like

NEVERMIND

Gui was printing twice because it was located in Replicated First, which ran the script once while getting cloned by the Load script to run again

(For anyone with the same problem) The solution was to relocate the Gui and it’s script into Replicated Storage so that it doesn’t run at all until called

1 Like