Ad
Log in to vote
0

Why does this script work once, but then it stops working? UI won't open again after closed

Asked by
ghxstlvty 133
8 days ago
local ClickDetector = script.Parent.ClickDetector
local GUI = game.ServerStorage.Fridge

ClickDetector.MouseClick:Connect(function(player)
    if player.PlayerGui:FindFirstChild("Fridge") == nil then
        GUI:Clone().Parent = player.PlayerGui
    end
end)
0
Idk if this will fix your issue but you can try adding a debounce to the script and also maybe do local CloneGUI = game.ReplicatedStorage.Fridge:Clone() CloneGUI.Parent = player.PlayerGui and also when you are closing the gui in the other script make sure you :Destroy() the GUI ezkatka1 50 — 8d
0
I tried that already. ghxstlvty 133 — 8d
0
But thanks for trying to help. ghxstlvty 133 — 8d

1 answer

Log in to vote
0
Answered by
2_MMZ 265 Moderation Voter
7 days ago

Your best option is to use RemoteEvents. I will show you how to do this.

First, insert a RemoteEvent into ReplicatedStorage, name it whatever you want.

Next, make sure you have a regular script inside of your Click Script.

And lastly, insert a LocalScript into your ScreenGUI.

Now, for the code.

Regular Script:

local remEvent = game.ReplicatedStorage:WaitForChild("RemoteEventName")
local ClickDetector = script.Parent.ClickDetector

ClickDetector.MouseClick:Connect(function(player)
remEvent:fireClient(player)
end)

Local Script:

local remEvent = game.ReplicatedStorage:WaitForChild("RemoteEventName")
local GUI = game.ServerStorage.Fridge

remEvent.OnClientEvent:Connect(function()
if script.Parent:WaitForChild("Fridge") == nil then
GUI:Clone().Parent = script.Parent
end
end)

If this is not 100% accurate, you can make some minor changes that will make it accurate. I hope this helped you!

Ad

Answer this question