local SoundService = game:GetService("SoundService")
local sound = SoundService.BackgroundMusic
script.Parent.MouseButton1Click:Connect(function()
local m = sound.Muted
local muted = m.Value
if muted == false then
muted = true
sound.Volume = 0
elseif muted == true then
muted = false
sound.Volume = 0.075
end
end)
When the game starts the BoolValue is false. And when I click the button it successfully changes the sound’s volume to 0, but does not changed the BoolValue, and so when I click it again it does not set the sounds volume to 0.075.
I also tried with ‘muted = blah’ being ‘m = blah’ and that did not work
I also had a similar problem while I was making some powers for my game.
I made a remote event that handles changes in values so it happens across the server.
game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent"):OnServerEvent:Connect(function(value)
Game:GetService("SoundService").BackgroundMusic.Muted.Value = value
end
And in the script where you want to change it just do
game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent"):FireServer(true) -- true or false whatever you want to change it to
I don’t think I need to say this but you can just make a variable for all that gamegetservice stuff so its shorter.
This did work for me. I’m not sure if it would work for you but lets see
When a value is being assigned to a variable it is either:
Pass by reference: The variable is given a pointer to the value, not the value itself. This essentially means when it is changed anywhere, any other variables with the pointer will also have that change.
Pass by value: The variable is given a copy of the value.
Tables are always passed by reference (unless it’s passed over the network), everything else is passed by value.
Under the hood all objects are tables which is why you can store the reference to sound.Muted, but not sound.Muted.Value
So I think I’m also having the same problem here, but i tried changing things around and I still wasnt able to figure out what the problem is.
local SoundService = game:GetService("SoundService")
local sound = SoundService.BackgroundMusic
local sounds = {1837719490, 9042454095, 9044702906}
local played = 123
while true do
local soundToPlay = sounds[math.random(1, #sounds)]
print (soundToPlay)
if soundToPlay ~= played then
played = soundToPlay
sound.SoundId = 'rbxassetid://' .. tostring(soundToPlay)
sound:Play()
wait(sound.TimeLength)
sound:Stop()
sound.TimePosition = 0
end
wait(.1)
end
When the game starts it just repeatedly skips the ‘if’ event and forever picks out new song ids.
I was hoping you might see what the problem here is while I cannot… is it a problem with the variables?
Thank you in advance. I only recently started trying to script