So, I'm making a game and it has these songs that play depending on the value of a BoolValue in ReplicatedStorage, this is my code:
local sound = script.Parent.Ambient local sound2 = script.Parent.Combat local value = game.ReplicatedStorage.Combat if value.Value == false then sound2.Volume = 0.5 wait() sound2.Volume = 0 wait() sound2:Stop() sound:Play() sound.Volume = 0.5 wait() sound.Volume = 1 else sound.Volume = 0.5 wait() sound.Volume = 0 wait() sound:Stop() sound2:Play() sound2.Volume = 0.5 wait() sound2.Volume = 1 end
I want the script to run everytime the value changes to either true or false. Notes: I have attempted the Changed event, but it did not work at all. (It doesn't play any song). If I use "while wait() do" then it'll just keep playing the song from the start. EDIT: Ok, I hope the script is proper now. Anyways, I said in the notes that I have used the Changed event, but it doesn't work. No song is playing, even when changing the value.
This can be done with the ":GetPropertyChangedSignal" function, the difference between the "changed" function and the ":GetPropertyChangedSignal" is that the "changed" function tests if all the properties changes but the ":GetPropertyChangedSignal" test if only 1 property changes. This can be useful for this question because as you stated the changed function didn't work for you assuming that you used it right. Here is the code I wrote, I did not have time to test this but I think it will work:
local sound = script.Parent.Ambient local sound2 = script.Parent.Combat local value = game.ReplicatedStorage.Combat value:GetPropertyChangedSignal("Value"):Connect(function() if value.Value == false then sound2.Volume = 0.5 wait() sound2.Volume = 0 wait() sound2:Stop() sound:Play() sound.Volume = 0.5 wait() sound.Volume = 1 else sound.Volume = 0.5 wait() sound.Volume = 0 wait() sound:Stop() sound2:Play() sound2.Volume = 0.5 wait() sound2.Volume = 1 end end)
You can do that by doing this: Using the changed will run this function everytime something is changed in this object. So this would do what you would want.
script.Parent.Parent.CheckBox2.checked.Changed:Connect(function() --your code here end)