Radio Mute System Not Working

Hello! I am trying to make a “Mute Radio” button, and I have a script, but when I press the button it says "attempt to index nil with ‘Volume’. Here is my mute script:

local on = true

script.Parent.MouseButton1Click:Connect(function()
	if on == true then
		game:GetService("SoundService"):FindFirstChild("Radios").Volume = 0
		script.Parent.Text = "Unmute Radios"
		on = false
	else
		on = true
		game:GetService("SoundService"):FindFirstChild("Radios").Volume = 0
		script.Parent.Text = "Mute Radios"
	end
end)

Here is the server side of the radio code:

local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local Remote = Tool:WaitForChild("Remote")
local Sound = Tool.Handle:FindFirstChild("Sound")

local LastRequestTime = 0

function floodCheck()
	local timeNow = tick()
	local elapsed = timeNow - LastRequestTime
	if elapsed > 0.5 then
		LastRequestTime = timeNow
		return false
	end
	return true
end

function onUnequip()
	Sound:Stop()
end

function onActivate()
	Remote:FireClient(getPlayer(), "ChooseSong")
end

function getPlayer()
	return game:GetService("Players"):GetPlayerFromCharacter(Tool.Parent)
end

function isPotentiallyValid(id)
	local idNumber = tonumber(id)

	if not idNumber then
		return false
	end

	if idNumber > 100000000000000000000 then
		return false
	end

	return true
end

function playSong(id)	
	id = id or ""

	if not isPotentiallyValid(id) then
		return
	end

	if not Sound then
		Sound = Instance.new'Sound'
		Sound.SoundGroup = game:GetService("SoundService"):FindFirstChild("Radios")
	end
	
	
	Sound.Parent = Handle
	Sound.Volume = 1
	Sound.Looped = true
	Sound.PlayOnRemove = false
	Sound.SoundId = "http://www.roblox.com/asset/?id="..id
	Sound:Play()
end

function onRemote(player, func, ...)
	if floodCheck() then return end
	if player ~= getPlayer() then return end

	if func == "Activate" then
		onActivate(...)
	end

	if func == "PlaySong" then
		playSong(...)
	end
end

Remote.OnServerEvent:connect(onRemote)
Tool.Unequipped:connect(onUnequip)

Thanks for any help!

Where is the local script located?

And is the volume part working. It seems finding the radios will only mute the radios folder. You can’t mute a folder but the contents in it.

Correct me if I’m wrong, but is it not muting because you only defined one music code.
That might have meant that it will only mute when that specific ID is typed in.

Once again, I’m not an expert on scripting so please correct me if I’m wrong. :sweat_smile:

script.Parent.MouseButton1Click:Connect(function()
if on == true then
fot i,v in pairs(game:GetService("SoundService"):FindFirstChild("Radios"):GetChildren())
if v:IsA("Sound") then
v.Volume = 0
on = false
end
end

else
on = true
fot i,v in pairs(game:GetService("SoundService"):FindFirstChild("Radios"):GetChildren())
if v:IsA("Sound") then
v.Volume = 1
on = false
end
end
end
end)

This may fix your problem

Oh I am dumb, I didn’t realize that it did not make the sound group for me. I don’t know if this is what you were talking about, but either way your answer brought that to my mind, and now it works. Thank you!

That just tells me if they put in a super huge number, then the script blocks it so it doesn’t have to run it. There are not that many sounds that lead up to that.

Ohhhh. Thank you for telling me this. :slight_smile: