Need help with a toggle on/off Gui

I’m currently making a settings gui with a toggleable button. The issue here is that the buttons keep acting weird and won’t become visible when pressed.

Code:

local function onSlider1Activated()
	Slider1.Active = true	
	Slider2.Visible = false	
end


Slider1.Activated:Connect(onSlider1Activated)

local function onSlider2Activated()
	Slider1.Active = false	
	Slider2.Visible = true	
end

Slider1.Activated:Connect(onSlider2Activated)

Here is what I’m trying to achieve in simpler terms…

image
image

1 Like

you did not define sliver1 and u put it twice sir.

Hmm… I’m unsure on what you’re trying to say but I’m not using any tweens but instead Visibility.

The

he not been defined sir, so this wont work.

1 Like

You’re setting the Active property, which doesn’t turn the Gui element on or off. Instead, do:

local function onSlider1Activated()
	Slider1.Visible = true	--changed here: active to visible
	Slider2.Visible = false	
end


Slider1.Activated:Connect(onSlider1Activated)

local function onSlider2Activated()
	Slider1.Visible = false	--changed here: active to visible
	Slider2.Visible = true	
end

Slider1.Activated:Connect(onSlider2Activated)
2 Likes
local function onSliderActivated()
	Slider1.Visible = not Slider1.Visible
	Slider2.Visible = not Slider2.Visible	
end

Slider1.Activated:Connect(onSliderActivated)
Slider1.Activated:Connect(onSliderActivated)
2 Likes
local function onSlider1Activated()
	Slider1.Visible = true	
	Slider2.Visible = false	
end


Slider1.Activated:Connect(onSlider1Activated)

local function onSlider2Activated()
	Slider1.Visible = false
	Slider2.Visible = true	
	
end

Slider2.Activated:Connect(onSlider2Activated)

I did it like this, but Slider 2 doesn’t become enabled and Slider 1 doesn’t become disabled either when the ImageButton is pressed.

Try Rami’s code, it should work as long as the initial condition is such that one slider is visible and the other is not.

1 Like

Why don’t you try with MouseButton1Click?

Like:

local function onSlider1Activated()
	Slider1.Visible = true
	Slider2.Visible = false	
end


Slider1.MouseButton1Click:Connect(onSlider1Activated)

local function onSlider2Activated()
	Slider1.Visible = false
	Slider2.Visible = true	
end

Slider1.MouseButton1Click:Connect(onSlider2Activated)

Sorry in advance if I’m not understanding the issue correctly.

Also would there be a way to make it so something happens when the Slider2 becomes visible, then something else happens when it is not visible anymore?

local function onSliderActivated()
	game.SoundService.Sound.Playing = false
	print("Disabled")
	Slider1.Visible = not Slider1.Visible
	print("Enabled")
	game.SoundService.Sound.Playing = true
	Slider2.Visible = not Slider2.Visible	

end
Slider1.Activated:Connect(onSliderActivated)
Slider2.Activated:Connect(onSliderActivated)

I’ve tried doing this myself but with no success

sure

local function onSliderActivated()
	game.SoundService.Sound.Playing = not game.SoundService.Sound.Playing
	Slider1.Visible = not Slider1.Visible
	Slider2.Visible = not Slider2.Visible	
end
Slider1.Activated:Connect(onSliderActivated)
Slider2.Activated:Connect(onSliderActivated)

Another way of doing this:

local slideractive = false

local function onSliderActivated()
	Slider1.Visible = not Slider1.Visible
	Slider2.Visible = not Slider2.Visible
	if slideractive then
		slideractive = false
		game.SoundService.Sound.Playing = false
	else
		slideractive = true
		game.SoundService.Sound.Playing = true
	end
end
Slider1.Activated:Connect(onSliderActivated)
Slider2.Activated:Connect(onSliderActivated)
1 Like

This will also work but mine is much shorter

1 Like