Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[SOLVED]localscripts wont mute and unmute sound but will change text?

This LocalScript is inside a ScreenGui: (1298214499 is the sound id)

local music = {"1298214499", "1298214499"}
local sound = script.Parent.BGM
local muted = false

while true do
	for i = 1, #music do
		sound.SoundId = "rbxassetid://"..music[i]
		sound:Play()
		wait(sound.TimeLength)
	end
end

This LocalScript is inside a TextButton inside the ScreenGui the first LocalScript is in:

local sound = script.Parent.Parent.BGM
local muted = false
script.Parent.MouseButton1Click:Connect(function()
	if muted then
		sound:Resume()
		muted= false
		script.Parent.Text = "Mute Music"
	else
		sound:Pause()
		muted = true
		script.Parent.Text = "Unmute Music"
		end
end)

here is the game : https://web.roblox.com/games/929825495/Dice-o-mathy-BETA?refPageId=b621b278-c670-4274-a0ac-41a7522d1def

2 answers

You have to use remote events ;)

1 comment

0

Do I put the RemoteEvent in ReplicatedStorage or the ScreenGui?

I found an answer that works and does not need remote events! This is the new first LocalScript. Also the sound is now in workspace

local music = game.Workspace.BGM

script.Parent.TextButton.MouseButton1Click:Connect(function()
	
if music.Volume == 0 then
	
	music.Volume = 2.5
	
	else
		
	 music.Volume = 0
end
end)

This is the new second LocalScript.

local sound = game.Workspace.BGM
local muted = false
script.Parent.MouseButton1Click:Connect(function()
	if muted then
		sound:Resume()
		muted= false
		script.Parent.Text = "Mute Music"
	else
		sound:Pause()
		muted = true
		script.Parent.Text = "Unmute Music"
		end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.