Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn´t this scrpt mute the sound?

Asked by 4 years ago

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)
0
Ok, can you explain why you're indexing a variable? DeceptiveCaster 3761 — 4y

1 answer

Log in to vote
1
Answered by
DogeIXX 172
4 years ago

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)
Ad

Answer this question