I made a Hide ui button im not sure how to script it

I made a button and script for hiding a particular screen gui but my script isnt working.
If anyone knows how to fix it please put the script on the comments.

the script


local Frame = script.Parent.Parent.Parent.Parent.VibeUi
local Button = script.Parent
local Text = Button.TextLabel



script.Parent.MouseButton1Click:Connect(function()

	-- Playing the sound for each click
	 script.Parent.Parent.Parent.Sound:Play()

	-- When clicked it will animate it in, when its clicked again it will animate out.
	if Frame then
		Button.ImageColor3 = Color3.fromRGB(0, 0, 0)
		Text.Text = "HIDE UI"
	else
		Frame.Enabled = true
		Button.ImageColor3 = Color3.fromRGB(255, 255, 255)
		Text.Text = "SHOW UI"
	end
end)

I think you should check if the ScreenGui is enabled or not.

local Frame = script.Parent.Parent.Parent.Parent.VibeUi
local Button = script.Parent
local Text = Button.TextLabel



script.Parent.MouseButton1Click:Connect(function()

	-- Playing the sound for each click
	script.Parent.Parent.Parent.Sound:Play()

	-- When clicked it will animate it in, when its clicked again it will animate out.
	if not Frame.Enabled then
        Frame.Enabled = true
		Button.ImageColor3 = Color3.fromRGB(0, 0, 0)
		Text.Text = "HIDE UI"
	else
		Frame.Enabled = false
		Button.ImageColor3 = Color3.fromRGB(255, 255, 255)
		Text.Text = "SHOW UI"
	end
end)
1 Like

Doesn’t the code just set the colors and not “animate it in”? I’d use a tween to accomplish this part.

Edit: Didn’t mean to reply to you @AxeI_c.

1 Like

Ty so much it works very well now.

1 Like