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

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

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by 4 years ago

You have to use remote events ;)

0
Do I put the RemoteEvent in ReplicatedStorage or the ScreenGui? Jakob_Cashy 79 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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)

Answer this question