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

Why doesn´t this scrpt mute the sound?

It is a local script and the Music.Value is a datastore inside a server script.

local player = game:GetService("Players").LocalPlayer 
local Hidden = player:WaitForChild("Hidden")
local gui = script.Parent
local Button = script.Parent:WaitForChild("BackFrame").TextButton


Button.Activated:Connect(function()
    if player.Hidden.Music.Value == true then
        Button.Text = "Unmute"
		player.Hidden.Music.Value = false
    elseif player.Hidden.Music.Value == false then
        Button.Text = "Mute"
		player.Hidden.Music.Value = true
    end

	if player.Hidden.Music.Value == true then
		script.Parent.Parent.Sounds.SoundHover.Volume=0
	end

    if player.Hidden.Music.Value == false then
    		script.Parent.Parent.Sounds.SoundHover.Volume=1
    end
end)

1 comment

0

Ok, can you explain why you're indexing a variable?

1 answer

✓ Accepted answer

If the audio just mutes if the buttons text is "Mute" then it is because the last two if statements are not needed and cause the error.

Also, at BoolValues an "elseif" is not needed, since there are only two ways of how it can be. (Really little timesaver ;) )

Here it is fixed:


local player = game:GetService("Players").LocalPlayer 
local Hidden = player:WaitForChild("Hidden")
local gui = script.Parent
local Button = script.Parent:WaitForChild("BackFrame").TextButton



Button.Activated:Connect(function()
    if player.Hidden.Music.Value == true then
        Button.Text = "Unmute"
        player.Hidden.Music.Value = false
script.Parent.Parent.Sounds.SoundHover.Volume=0
    else
        Button.Text = "Mute"
        player.Hidden.Music.Value = true
script.Parent.Parent.Sounds.SoundHover.Volume=1
    end
end)

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