I tried making a function that activates on a RemoteEvent being triggered. It's triggered by the player's mute music button. Here's the code in ServerScriptService for when it's triggered:
-- Mutes/unmutes the player's music game.ReplicatedStorage.muteMusic.OnServerEvent:Connect(function(player) local isMuted = workspace.isMuted.Value local playing = workspace.audio1.Playing if isMuted == true then -- Music is muted -- Make music unmuted isMuted = false playing = true -- Just making sure print("Unmuted") else -- Music is not muted -- Make music muted isMuted = true playing = false -- Just to make sure it works print("Muted") end end)
It prints "Muted" every time I press it. Please help me if you can. Thx.
Insert a Sound object into StarterGui and call it Music then inside the button you want them to press the (mute/unmute one) create a local script and paste this code inside it.
local Player = game:GetService('Players').LocalPlayer local PlayerGui = Player:WaitForChild('PlayerGui') local Music = PlayerGui:WaitForChild('Music') local isPlaying = false script.Parent.MouseButton1Click:Connect(function() if not isPlaying then isPlaying = true Music:Resume() else Music:Pause() isPlaying = false end end)
This is happening because when you defined local isMuted = workspace.isMuted.Value
it will always be the same value, you have to define isMuted
like this: local isMuted = workspace.isMuted
and replace isMuted
on every other bit of the script with isMuted.Value
.The finished/fixed script should be:
-- Mutes/unmutes the player's music game.ReplicatedStorage.muteMusic.OnServerEvent:Connect(function(player) local isMuted = workspace.isMuted local playing = workspace.audio1.Playing if isMuted.Value == true then -- Music is muted -- Make music unmuted isMuted.Value = false playing = true -- Just making sure print("Unmuted") else -- Music is not muted -- Make music muted isMuted.Value = true playing = false -- Just to make sure it works print("Muted") end end)