Instance:Clone() Is cloning twice?

Hello. I’m making a loading screen / main menu.

Everything works except for when i hit play. I made it so theres a frame that covers the entire screen when you hit play, and after a while it fades out. But when I clone it from ReplicatedFirst into PlayerGui, it clones twice and theres two of “JoinFrame” in the PlayerGui. Here is the code:

local playerGui = game.Players.LocalPlayer.PlayerGui
local frame1 = game:GetService("ReplicatedFirst"):WaitForChild("JoinFrame"):Clone()

frame1.Parent = playerGui

local btn = script.Parent
local rem = game:GetService("ReplicatedStorage"):WaitForChild("CharAdd")
local gui = script.Parent.Parent.Parent
local startFrame = playerGui:WaitForChild("JoinFrame"):WaitForChild("Frame")
local tws = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(5,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
local tweenFrame = tws:Create(startFrame, tweeninfo, {BackgroundTransparency = 1})
local playhit = script.Parent:WaitForChild("PlayHit")
local hover = script.Parent:WaitForChild("Hover")

btn.MouseButton1Click:Connect(function(plr)
	playhit:Play()
	rem:FireServer(plr)
	frame1.Enabled = true
	gui.Enabled = false
	wait(5)
	tweenFrame:Play()
	gui:Destroy()
end)

btn.MouseEnter:Connect(function()
	hover:Play()
end)

And here is how it look in the PlayerGui:

image

1 Like

is there a JoinFrame in starterGUI already?

No, StarterGui is completely empty, and there is no other script referencing this GUI.

Try just parenting the GUI, there should be no need to clone it because youre only messing with the clients copy
This might eliminate the problem, but if not it narrows down the things it could be

What is the parent of the localScript?

Uh, I don’t think replicatedFirst or replicatedStorage resets on player death.

The button is the parent. Here, I can show you a picture of the explorer.
image

Try disabling the play script then reEnable it when you put it as the playerGUI’s child because the script is probably running inside of ReplicatedFirst and then again when you clone it?

I can try and put a print(), if it prints 2 times it is my problem.

The problem is because scripts in replicatedFirst run automatically and then you are cloning the mainMenuGui and the play script is running again.

1 Like

Yes, that is my problem. Thanks!