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

Mute/Unmute button not working but no erroring?

Asked by
fifayy 28
3 years ago

Used Local script only

local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://2830837614"

sound.Looped = true
sound:Play()
sound.Playing = true
local bool = script.Parent.Changer
bool.Value = true





if bool.Value == true then
    script.Parent.Activated:Connect(function()
        bool.Value = false
        sound.Playing = false
    end)
end



if bool.Value == false then
    script.Parent.Activated:Connect(function()
        bool.Value = true
        sound.Playing = true
    end)
end

0
what's the error? LeedleLeeRocket 1257 — 3y
0
no error fifayy 28 — 3y

2 answers

Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
3 years ago

Try this

local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://2830837614"

sound.Looped = true
sound:Play()
sound.Playing = true
local bool = script.Parent.Changer
bool.Value = true





if bool.Value == false then
    script.Parent.Activated:Connect(function()
        bool.Value = false
        sound.Playing = false
    end)
end



if bool.Value == true then
    script.Parent.Activated:Connect(function()
        bool.Value = true
        sound.Playing = true
    end)
end

Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

In your script, since you set the bool as true, the script will run and wait for it to activate until it can set it to false. The script only runs once, and that is your problem;;;;;; i think you can just use the activated event, and then check if the bool is true to change it, so that the script runs multiple times when needed

local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://2830837614"

sound.Looped = true
sound:Play()
sound.Playing = true
local bool = script.Parent.Changer
bool.Value = true



script.Parent.Activated:Connect(function() -- activated?
    if bool.Value == true then -- if its true
        bool.Value = false -- change to false
        sound.Playing = false
    else -- if its false
        bool.Value = true
        sound.Playing = true
    end
end)

Answer this question