-
When button is clicked I want it to hide the screen gui’s and once clicked again i want the gui’s to reappear
-
I’m not sure how to do it
-
I looked for solutions on dev forum but haven’t found anything yet
button = script.Parent
script.Parent.MouseButton1Click:Connect(function()
button.Parent.Parent.Spiral.Enabled = false
button.Parent.Parent.Swimmingpool.Enabled = false
button.Parent.Parent.Building.Enabled = false
button.Parent.Parent.Trails.Enabled = false
button.Parent.Parent.stairs.Enabled = false
end)
This may sound dumb but i’m not a heavy coder at the moment and haven’t had the time to properly study coding.
1 Like
Is this a script or a localscript?
1 Like
Its a Local script inside a screen gui that controls the button (each button is parented to a different screengui.
That should work if button is a textbutton.
1 Like
Its working but I don’t know how to make it reappear once clicked again
1 Like
Try this script:
local clicked = false
button = script.Parent
script.Parent.MouseButton1Click:Connect(function()
if clicked then
button.Parent.Parent.Spiral.Enabled = true
button.Parent.Parent.Swimmingpool.Enabled = true
button.Parent.Parent.Building.Enabled = true
button.Parent.Parent.Trails.Enabled = true
button.Parent.Parent.stairs.Enabled = true
else
button.Parent.Parent.Spiral.Enabled = false
button.Parent.Parent.Swimmingpool.Enabled = false
button.Parent.Parent.Building.Enabled = false
button.Parent.Parent.Trails.Enabled = false
button.Parent.Parent.stairs.Enabled = false
end
end)
3 Likes
It still does not reappear once clicked again.
1 Like
Try changing your code to the one below. Basically, It’ll set the Enabled
property to the opposite of it. (if false, then true, elseif false, then true)
local button = script.Parent
script.Parent.MouseButton1Click:Connect(function()
button.Parent.Parent.Spiral.Enabled = not button.Parent.Parent.Spiral.Enabled
button.Parent.Parent.Swimmingpool.Enabled = not button.Parent.Parent.Swimmingpool.Enabled
button.Parent.Parent.Building.Enabled = not button.Parent.Parent.Building.Enabled
button.Parent.Parent.Trails.Enabled = not button.Parent.Parent.Trails.Enabled
button.Parent.Parent.stairs.Enabled = not button.Parent.Parent.stairs.Enabled
end)
4 Likes
You should loop through the buttons parent and disable and enable it if its name is in the table example:
local button = script.Parent
local Names = {'Spiral','Swimmingpool','Building','Trails','stairs'}
button.MouseButton1Click:Connect(function()
for _,Object in ipairs(button.Parent.Parent:GetChildren()) do
if table.find(Names,Object.Name) then
Object.Enabled = not Object.Enabled
end
end
end)
2 Likes
Thanks, I’m planning on adding more buttons and I probably shouldn’t write them all out like I did, Thanks!
1 Like