Hello!
I have a radio gampeass in my game which grants access to a Radio ingame. The radio works it self, however I am trying to make a mute radio button for people to mute music such as bypasses. This does work, however, the issue with the script is that when a Player with the radio playing a sound resets / rejoins, their audio can then be heard again by players. I'm not exactly sure what is causing this. Here is the script I am using:
--###----------[[SERVICES]]----------###-- local Players = game:GetService("Players") --###----------[[VARIABLES]]----------###-- -- Objects local MuteButton = script.Parent -- Regular local MuteToggle = true --###----------[[FUNCTIONS]]----------###-- -- Sound Management local function ManageRadioMute() for _,Player in pairs(Players:GetPlayers()) do local Character = Player.Character if (Character) then --------------- local Radio = Character:FindFirstChild("Radio") if (Radio) then --------------- local Sound = Radio:FindFirstChildWhichIsA("Sound") if (Sound) then Sound.Volume = (MuteToggle and 0 or 1) end end end end MuteToggle = (not MuteToggle) end --###----------[[SETUP]]----------###-- MuteButton.MouseButton1Click:Connect(ManageRadioMute)
Hey, does the GUI have ResetOnSpawn enabled? If so, that could be the issue. Let me know if this fixes it.
in theory, you could have it manually replicate (RemoteEvents) the volume to every player, and the client script will decide whether or not to actually apply it or ignore the volume (based on the player's preferences). for this i would recommend having the actual volume of the Sound object to 0 to prevent unwanted issues, when a player wants to play music, send a request via RemoteEvent to the server to play to all users, each player will receive the OnServerEvent and the LocalScript will decide based on the player's preferences to set the volume as 1 or 0.
a code example: in server script
local RemoteEvent = game:GetService('ReplicatedStorage').SoundEvent; -- this is the remoteevent to use RemoteEvent.OnClientEvent:Connect(function(player, sound) RemoteEvent:FireAllClients(sound); end);
in client script
local muted = false; local RemoteEvent = game:GetService('ReplicatedStorage').SoundEvent; -- this is the remoteevent to use RemoteEvent.OnServerEvent:Connect(function(sound) -- i would recommend having an id blacklist here instead of the server if (not muted) then sound.Volume = 1; end end);
you can use your posted code to mute all radios whenever it is pressed, this is just to make sure it stays muted
You could use a character added event, since you said it is caused when they reset, you can make it so either when the player is added redo the script or have a event in the music player that fires to all clients when the id changes, that way you can check it per client