Toggling a button through changing transparencies

So, I made a music player where at the moment, whenever you toggle to mute the player, it switches from one label - unmuted, to another label - muted.

I’m trying to make it so instead of using 2 labels to accomplish 1 function, I want to be able to just toggle different transparencies for when it is activated or deactivated.
For example: 0.5 is unmuted while 0 is muted

MusicStop.MouseButton1Click:Connect(function()
	if MusicStop.IsStopped.Visible then
		MusicStop.IsStopped.Visible = false
		SoundPlayer:Play(); raiseSound:Play()
	else
		MusicStop.IsStopped.Visible = true
		dimSound:Play(); dimSound.Completed:Wait()
		SoundPlayer:Stop()
	end
end)

This is the code i’m working with, I think I just need to change the if else statement and the conditions, but i’m not sure how to do that.

just do musiclabel.Transparency = in the if statements

I tried doing this:

MusicStop.MouseButton1Click:Connect(function()
	if MusicStop.ImageTransparency == 0.5 then
		SoundPlayer:Play(); raiseSound:Play()
	else
		MusicStop.ImageTransparency = 0
		dimSound:Play(); dimSound.Completed:Wait()
		SoundPlayer:Stop()
	end
end)

And I think I messed it up

Did you mean to do this?

MusicStop.MouseButton1Click:Connect(function()
	if MusicStop.ImageTransparency == 0.5 then
		MusicStop.ImageTransparency = 0
		SoundPlayer:Play(); raiseSound:Play()
	else
		MusicStop.ImageTransparency = 0.5
		dimSound:Play(); dimSound.Completed:Wait()
		SoundPlayer:Stop()
	end
end)

ImageTransparency is not a property you have to do Image.Transparency

W h a t

I think he’s referring to GuiButtons, not actual Parts inside the workspace

you’re right on GuiButtons it’s called BackgroundTransparency not ImageTransparency or Transparency

change it to

gui.BackgroundTransparency = 0

ImageTransparency is a property of ImageLabels and ImageButtons, if this is an Imagebutton, it’ll work fine

It depends on the scenario though

If you want to make the Image transparent, use ImageTransparency

If you want to make the Background of the Frame transparent, use BackgroundTransparency

oh okay, but BackgroundTransparency will still have to be set to 1 if you want it to be invisible.

Unless BackgroundTransparency was 1 the whole time

At default: 0.5 ImageTransparency
When clicked on: Switched to 0 ImageTransparency || Song is Muted
When clicked on again: Switches back to 0.5 ImageTransparency and the Song Resumes

Is the behavior i’m trying to achieve. :>

I should’ve clarified more

MusicStop.MouseButton1Down:Connect(function()
	if MusicStop.ImageTransparency == 0.5 then
		MusicStop.ImageTransparency = 0
		SoundPlayer:Resume(); raiseSound:Play()
	else
		MusicStop.ImageTransparency = 0.5
		dimSound:Play(); dimSound.Completed:Wait()
		SoundPlayer:Pause()
	end
end)

Btw is this in a Local or Server Script? Should be Local if it isn’t :thinking:

This is a local script, I have the handler client sided.

Try this out and see what Outputs?

MusicStop.MouseButton1Down:Connect(function()
    print("Fired")
	if MusicStop.ImageTransparency == 0.5 then
		MusicStop.ImageTransparency = 0
		SoundPlayer:Resume(); raiseSound:Play()
        print("Resuming")
	else
		MusicStop.ImageTransparency = 0.5
		dimSound:Play(); dimSound.Completed:Wait()
		SoundPlayer:Pause()
        print("Pausing")
	end
end)

I’ll give it a shot, I guess it doesn’t help because the way I have these buttons set up is that they’re already at 0.5 until you hover over them and then the transparency gets set to 0, but the behavior im seeing on the other ways its been arranged is that it doesn’t actually toggle

EDIT: This was after clicking it twice:
image

I figured it out, sorta.

MusicStop.MouseButton1Down:Connect(function()
	print("Fired")
	if MusicStop.ImageTransparency == 0 then
		MusicStop.ImageTransparency = 0.5
		SoundPlayer:Resume(); raiseSound:Play()
		print("Resuming")
	elseif
		MusicStop.ImageTransparency == 0.5 then
		MusicStop.ImageTransparency = 0
		dimSound:Play(); dimSound.Completed:Wait()
		SoundPlayer:Pause()
		print("Pausing")
	end
end)

I had to disable my other script where whenever you hovered your mouse over the button it would highlight, and it was messing with the behavior of the buttons themselves.

--script.Parent.MouseEnter:Connect(function()
--	script.parent.ImageTransparency = 0
--	script.Parent.ImageColor3 = Color3.fromRGB(255, 255, 255)
--end)
--script.parent.MouseLeave:Connect(function()
--	script.Parent.ImageTransparency = 0.5
--	script.Parent.ImageColor3 = Color3.fromRGB(255,255,255)
--end)

I don’t know how to get these two to work nicely, but that is a problem for another day