UI Only Clones Once

I’m trying to get my UI to clone everytime “x” object is clicked, but it clones the UI only once.
I’m new to coding with Non-Experimental, so I’m hoping this is just something I’m easily overlooking. Thanks. :slight_smile:

Edit: I have it so the other UI will automatically remove after 5 seconds, once I try and clone it again after 5 seconds, it won’t clone.

local ui = game.ReplicatedStorage:WaitForChild("SkeletonUi")

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
    if not plr.PlayerGui:FindFirstChild("SkeletonUi") then
    ui:Clone().Parent = plr.PlayerGui
    end
end)

It is a standard Script and Game is Non-Experimental.

2 Likes

It’s only cloning the GUI once because you are cloning it if it doesn’t exist in the PlayerGui and then parenting that clone in the PlayerGui, which means the next check will fail.

2 Likes

The issue is that the if statement stops the GUI from cloning if it has already been cloned.

local ui = game.ReplicatedStorage:WaitForChild("SkeletonUi")
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
    ui:Clone().Parent = plr.PlayerGui
end)
2 Likes

Seems to me that the if statement is checking if the UI already exists before placing another one. Did you remove the UI before attempting to place another?

1 Like

@mircostaff @EmeraldSlash @Proxidius Sorry, I forgot to include that the UI automatically removes after 5 seconds.

2 Likes

Strange, did you try using print on each scope to see about where the code stops? I’m guessing the if statement so start there. Print is fairly solid for debugging.

1 Like

Yep, right at the if statement. Any idea of what’s going on?

1 Like

You could add a debounce that also lasts four five seconds.

1 Like

Hang on, does the code work fine in a non-FE environment?

1 Like

Yes.

1 Like

Alright, so is the UI removed locally or globally? I think the problem may be that the server still sees it as existing when for the set client, it doesn’t.

1 Like

I remove it with this:

for i = 1,6 do
    script.Parent.Text = "Automatically closes in " .. 6 - i.. ".."
    wait(1)
    if i == 6 then
        script.Parent.Parent.Parent:Destroy()
    end
end
1 Like

Is it a local or server script?

Edit: It looks to be local.

1 Like

local, should it be server?

1 Like

Yes, I believe that you’re only removing it for the client, rather than the server as well, that’s how FE works after all.

Edit: Not to be too confusing, but essentially, if something is done through a localscript, then it will only be applied to that client, while a regular script, is ran on the server, and thus replicated to most clients through the server. Proper replication is done by handling both of these things to put less stress on both the client and the server.

1 Like

Fixed it! Thank you!

2 Likes

In an FE environment, server scripts can not run in a GUI. He would need to use a remote event to delete it.

1 Like

No problem my dude :wink:.

2 Likes

I mean, that’s kinda what I said.

1 Like

Although it’s not directly related to your question, you can actually use a for loop to down to a number.

1 Like