What i want to do is create a way to close the menu up once its opened by just clicking the button you clicked?
Ive already tried several ways but none of them work like destroying it if it finds the menu in the local players GUI
local Button = script.Parent
local CraftingMenu = game.ReplicatedStorage.CraftingMenu
Button.MouseButton1Click:Connect(function(Clicked)
local CraftingMenuClone = CraftingMenu:Clone()
CraftingMenuClone.Parent = game.Players.LocalPlayer.PlayerGui
end)
So what i want is a system where if you click the crafting button you well open the menu but you can click the crafting button again this time close the crafting menu
If you want the button to act both as an open-close button, you can add a condition to it. Say:
local menuopen = false
Button.MouseButton1Down:Connect(function(Clicked)
if not menuopen then
menuopen = true
--- open the menu
else
menuopen = false
-- close the menu
end)
When i use this and put the script in that opens and close it closes for .5 seconds and then just reopens
local Button = script.Parent
local CraftingMenu = game.ReplicatedStorage.CraftingMenu
local menuopen = false
Button.MouseButton1Down:Connect(function(Clicked)
if not menuopen then
menuopen = true
Button.MouseButton1Click:Connect(function(Clicked)
local CraftingMenuClone = CraftingMenu:Clone()
CraftingMenuClone.Parent = game.Players.LocalPlayer.PlayerGui
end)
else
menuopen = false
game.Players.LocalPlayer.PlayerGui.CraftingMenu:Destroy()
end
end)
local Button = script.Parent
local CraftingMenu = game.ReplicatedStorage.CraftingMenu
local menuopen = false
local CraftingMenuClone = nil
Button.MouseButton1Down:Connect(function()
if not menuopen then
menuopen = true
CraftingMenuClone = CraftingMenu:Clone()
CraftingMenuClone.Parent = game.Players.LocalPlayer.PlayerGui
else
menuopen = false
if CraftingMenuClone then
CraftingMenuClone:Destroy()
CraftingMenuClone = nil
end
end
end)
you were connecting the MouseButton1Click event inside the MouseButton1Down event, which is likely causing the menu to reopen immediately after closing.