I created code that would make a shop and settings GUI appear to only the client that pressed the corresponding buttons by putting both frames into Replicated Storage and cloning them to the client. When the person re-presses the button the frame clone would do a tween animation and be destroyed. A small problem came up when I pressed both button before closing the first creating a stack of both frames. I tried to fix the issue by adding to my scripts code that would check if the other frame’s clone existed in the PlayerGUI and destroy it if it did before cloning the new one. But I didn’t know how to tell the other script to change it’s debounce value to false, making it where it just breaks the other script and I can only access one frame. Any ideas on how to fix the issue? Is there just a totally easier way to do it, or do I just have to use a remote event or something; Im confused.
For the Settings Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local debounce = false
script.Parent.MouseButton1Click:Connect(function()
if debounce == false then
if player.PlayerGui.Menu:FindFirstChild("ShopGUI") then
local ShopGUI_Target = player.PlayerGui.Menu:WaitForChild("ShopGUI")
ShopGUI_Target:TweenPosition(UDim2.new(-0.283, 0,0.187, 0), nil, Enum.EasingStyle.Linear, 0.10)
wait(0.05)
ShopGUI_Target:Destroy()
local SettingsGUI = game.ReplicatedStorage.SettingsGUI:Clone()
SettingsGUI.Parent = player.PlayerGui.Menu
SettingsGUI.Position = UDim2.new(-0.283, 0,0.187, 0)
SettingsGUI:TweenPosition(UDim2.new(0,0,0.187,0), nil, Enum.EasingStyle.Linear, 0.10)
debounce = true
else
local SettingsGUI = game.ReplicatedStorage.SettingsGUI:Clone()
SettingsGUI.Parent = player.PlayerGui.Menu
SettingsGUI.Position = UDim2.new(-0.283, 0,0.187, 0)
SettingsGUI:TweenPosition(UDim2.new(0,0,0.187,0), nil, Enum.EasingStyle.Linear, 0.10)
debounce = true
end
elseif debounce == true then
local SettingsGUI_Clone = player.PlayerGui.Menu:WaitForChild("SettingsGUI")
SettingsGUI_Clone:TweenPosition(UDim2.new(-0.283, 0,0.187, 0), nil, Enum.EasingStyle.Linear, 0.10)
wait(0.05)
SettingsGUI_Clone:Destroy()
debounce = false
end
end)
For the Shop Script (Note: This one doesn’t have the code that checks if the other GUI exists because I knew it currently was broken)
local ReplicatedStorage = game.ReplicatedStorage
local player = game.Players.LocalPlayer
local debounce = false
script.Parent.MouseButton1Click:Connect(function()
if debounce == false then
local ShopGUI = game.ReplicatedStorage.ShopGUI:Clone()
ShopGUI.Parent = player.PlayerGui.Menu
ShopGUI.Position = UDim2.new(-0.283, 0,0.187, 0)
ShopGUI:TweenPosition(UDim2.new(0,0,0.187,0), nil, Enum.EasingStyle.Linear, 0.10)
debounce = true
elseif debounce == true then
local ShopGUI_Clone = player.PlayerGui.Menu:WaitForChild("ShopGUI")
ShopGUI_Clone:TweenPosition(UDim2.new(-0.283, 0,0.187, 0), nil, Enum.EasingStyle.Linear, 0.10)
wait(0.05)
ShopGUI_Clone:Destroy()
debounce = false
end
end)