Music Volume Gui not working

I’m trying to make a music volume changer gui, but the buttons are not working. The code is in a localscript and seems like it should be working. Help would be appriciated.

localscript:

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Sound:Play()
	script.Parent.Parent.MusicVol.Value = script.Parent.Parent.MusicVol.Value + 0.1
end)

musicvol is a number value that = the game’s music, and the sound:play is for a button sound.

Do you have a script that listens for changes on the MusicVol value?

nope. how would i do that? :face_with_raised_eyebrow:

You would use GetPropertyChangedSignal.

Example:

local part = script.Parent

part:GetPropertyChangedSignal("BrickColor"):Connect(function() -- this means you're listening for when the part's BrickColor is changed

print("My new color is: " .. part.BrickColor)

end)
1 Like

So would it look like:

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Sound:Play()
	local sound = script.Parent.Parent.MusicVol

	sound:GetPropertyChangedSignal("Value"):Connect(function()
	
		print("Music Volume changed")

		script.Parent.Parent.MusicVol.Value = script.Parent.Parent.MusicVol.Value - 0.1
end)

Nope.

You have to put the code for GetPropertyChangedSignal in another script.

Otherwise your button will just listen for the value every time you click it.

Like this:

local script (not in button)

local value = -- put musicVol here

local sound = -- sound

value:GetPropertyChangedSignal("Value"):Connect(function()

sound.Volume = value.Value

end)

And then change the value in the local script in the button.

1 Like

here is script:

local value = script.Parent.MusicVol

local sound = script.Parent.Sound

value:GetPropertyChangedSignal("Value"):Connect(function()

sound.Volume = value.Value
game.Workspace.MusicBackground.Zones.Center.Music.Chill.Volume = value.Value
game.Workspace.MusicBackground.Zones.Center.Music.Chill2.Volume = value.Value
game.Workspace.MusicBackground.Zones.Center.Music.Attached.Volume = value.Value
game.Workspace.MusicBackground.Zones.Center.Music.Idealism.Volume = value.Value
game.Workspace.MusicBackground.Zones.Center.Music.Technicolor.Volume = value.Value

end)

It doesn’t need to be in another script, you can have multiple connections in the same script. But it does need to be outside of the mouseButtonClick connected function. What you have above looks good, you can also use Value- Changed Event.

Also make sure SoundService.RespectFilteringEnabled is set to true, if ur using a UI to change music everyone can hear.

The problem with what you have right now is that you’re changing Musicvol’s value, but so what? There isn’t any script listening for when MusicVol’s value is changed to actually change the sound’s Volume property. Like @lordmochibi suggested you can use GetPropertyChangedSignal(“Property”) to listen for whenever musicVol’s value changes and change the sound’s Volume to musicVol’s value. (If you don’t do that last part nothing would really happen.) So this would be your script:

-- Raise musicVal's value whenever script.Parent is clicked
script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Sound:Play()
	script.Parent.Parent.MusicVol.Value = script.Parent.Parent.MusicVol.Value + 0.1
end)

-- Change sound's volume to musicVal's value whenever musicVal's value changes
script.Parent.Parent.MusicVol:GetPropertyChangedSignal("Value"):Connect(function()
   script.Parent.Parent.Sound.Volume = script.Parent.Parent.MusicVol.Value
end)

Edit: Nvm, didn’t see you already figured it out

1 Like

it works but the music volume aint changing

Make sure that’s a local script.