Script works in play test but not when published on roblox

I am making a mute and unmute button for music in a game but it doesn’t work when playing on Roblox, but works with a play test in studio, what’s happening?
I found a post similar to this: the post

Heres my current script; It’s also a localscript

script.Parent.TouchTap:Connect(function()
	for _, v in pairs(game.Workspace.Music:GetDescendants()) do
		if v.Volume == 0 then
			v.Volume = 0.5
			script.Parent.Text = "Mute music"
		elseif v.Volume == 0.5 then
			v.Volume = 0
			script.Parent.Text = "Unmute music"
		end
	end
end)
script.Parent.MouseButton1Click:Connect(function()
	for _, v in pairs(game.Workspace.Music:GetDescendants()) do
		if v.Volume == 0 then
			v.Volume = 0.5
			script.Parent.Text = "Mute music"
		elseif v.Volume == 0.5 then
			v.Volume = 0
			script.Parent.Text = "Unmute music"
		end
	end
end)
2 Likes

This script works. Reasons why yours don’t work might be that you checked v.Volume if it’s toggled, you used GetDescendants() instead of GetChildren() or you put the localscript in a place where it can not run (ex. workspace).

The Script
local button = script.Parent
local MusicFolder = --your music folder path
local muted = false
button.MouseButton1Down:Connect(function()
	if muted then
		for i,v in pairs(MusicFolder:GetChildren()) do
			v.Volume = 0.5
		end
		muted=false
		button.Text="Unmute"
	else
		for i,v in pairs(MusicFolder:GetChildren()) do
			v.Volume=0
		end
		muted=true
		button.Text="Mute"
	end
end)
button.TouchTap:Connect(function()
	if muted then
		for i,v in pairs(MusicFolder:GetChildren()) do
			v.Volume = 0.5
		end
		muted=false
		button.Text="Unmute"
	else
		for i,v in pairs(MusicFolder:GetChildren()) do
			v.Volume=0
		end
		muted=true
		button.Text="Mute"
	end
end)
2 Likes

Sorry for the late solution! I’ve been trying to learn Lua outside of Roblox

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.