Hello, so I’m trying to make a sound pause locally when a server-changed boolValue turns true.
Here’s the function:
genOn.Changed:Connect(function(NewValue)
if NewValue and UI.Enabled == true then
workspace.Music["SceneMusic"..cameraVal.Value]:Play()
musicBG:Pause()
print("Generator is on and you are spectating")
else
if UI.Enabled == true then
duckMusic:Stop()
teddyMusic:Stop()
print("Generator is off and you are spectating")
end
end
end)
Everything inside the function works as intended, it prints all it has to print and plays the “SceneMusic” as it should, but when it comes to pausing MusicBG it just doesn’t. I have tried Stopping it, but that doesn’t work either, the only way I can stop the sound from playing (Only locally) Is by destroying it, but I need to play it again after something else happens.
You could try setting the Volume of the sound to 0. Be mindful of the fact that this value defaults to 0.5, you might make it louder than intended if you set it higher when turning the sound back on.
I didn’t put more information of musicBG because it’s basically called 20 times in a script long 500 lines and I thought it’d be confusing and pointless, although if it’s really necessary I can send the whole script I guess. Thanks for pointing out that I used .Changed wrong.
genOn.Changed:Connect(function()
if genOn.Value and UI.Enabled then
workspace.Music["SceneMusic"..cameraVal.Value]:Play()
musicBG:Pause()
print("Generator is on and you are spectating")
elseif UI.Enabled then
duckMusic:Stop()
teddyMusic:Stop()
print("Generator is off and you are spectating")
end
end)
In the same folder as SceneMusic, I checked the local and it’s correct, it also pauses correctly in other functions that use musicBG as well. The script is a local script as stated in the title
It’s not in the workspace, it’s in a GUI.
I will try to explain better what the scripts do, should have done that when creating the topic, give me a couple of minutes : P
Ok you confused me. You said the script was in the same folder as SceneMusic and you reference SceneMusic in workspace.Music → workspace.Music["SceneMusic"..cameraVal.Value]:Play()
EDIT: wait my bad, you were talking about musicBG.
So, Basically, the local script allows you to change the camera with the tweenservice while you’re ‘Spectating’, it also lets you exit the ‘Spectating’ Status. Another part of the game which is important to know is that you can turn on and off an electricity generator, which stops or plays all sounds, actions, lights etc. etc.
I’ve made it so that when you spectate a specific ‘Scene’ it has its own music, i.e. it stops the background music and plays another specific sound.
Now, When a player is spectating, and another player turns off the generator, everything is fine, but the problem occurs when the other player turns on the generator again, which starts the music from a server script (actually a module which is called from a server script, the server script is the generator’s script).
So I figured I’d pause the music as soon as the local script detects that the generator is on again, but unfortunately that doesn’t work! :C
So I assume because the other player starts the music (it plays on server) you can’t use :Pause() on client because Server has priority, maybe. Perhaps the only solution is to just change the volume to 0 locally so the local player wont hear it.
Also I like the game’s art direction. Gives me wonderland / fun house vibes
I don’t know, it’s like it works when it wants, because for example when you spectate, it pauses the music which was previously played server-side. Also I think that changing the volume is an effective solution but not kind of solution that I would like to have
Thanks for the compliments on the art direction, I really like the fun house concept
Although all of this project is purely to improve on my scripting skills and I will probably forget it even exists when I’m satisfied with it xD
Perhaps creating all sounds client sided, having the server not control sounds like this. But rather having the server fire a remote event to the client(s) to Play/Pause/Stop that way the client can determine if it should play/pause/stop depending on certain situations like spectating. I know its not good to trust the client but in this case its fine because its just audio.