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

Why doesn't it work ? Mute/Unmute song gui

Asked by
Bulvyte 388 Moderation Voter
8 years ago
local player = game.Players.LocalPlayer
local sound = player.Aviici

function Click()

    player.sound.Volume = 0

end
function Click()

    player.sound.Volume = 0.25

end


script.Parent.MouseButton1Down:connect(Click)
script.Parent.MouseButton1Down:connect(Click)

so, i want the player make when it clicks the gui, makes the song be muted in Players > Player like here: http://prntscr.com/89kfif

0
I have a script in my game to where you can hit the "m" key and it mutes music. However it is complicated and the right circumstances need to be met. CarterTheHippo 120 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

At line 1-2:

local player = game.Players.LocalPlayer.Aviici
local sound = player.Aviici

You already set player as the sound. So at line 2, the script will see if there's a other sound inside the sound on player.

In line 6 and 11, it's when the script will get confused. In scripting, you need to understand, you don't use a variable and a other variable to locate something. For example

local x = script.Parent
local y = x.Parent

   x.y.BrickColor = BrickColor.new("Really black") -- WRONG
--/\/\
--That CANNOT happen

y.BrickColor = BrickColor.new("Really black") -- RIGHT

So your script would be:

local player = game.Players.LocalPlayer
local sound = player.Aviici

function Click()

    sound.Volume = 0

end
function Click()

    sound.Volume = 0.25

end


script.Parent.MouseButton1Down:connect(Click)
script.Parent.MouseButton1Down:connect(Click)

IMPORTANT TIP: Use Output. It will say the errors you cause.

0
Doesn't work on imagebutton or textbutton i have tried this various ways still doesn't work no errors in output and by the way new error came: Content failed because HTTP 403 (HTTP/1.1 403 Asset is not trusted for this place) Bulvyte 388 — 8y
0
Is this in a local script. If not, then you can't use LocalPlayer DragonOfWar900 397 — 8y
0
Also, that error is from something else. The error of this script will look like "locationToTheScript: error" and below that a few blue lines DragonOfWar900 397 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

you have two functions with same name. and your calling them both at the same twice. just use one function and make a check to see which action to do... like so...

local player = game.Players.LocalPlayer
local sound = player.PlayerGui:WaitForChild("Aviici")
sound:Play()

local function Click()
    if sound.Volume == 0 then
        sound.Volume = 0.25
    else
        sound.Volume = 0
    end 
end



script.Parent.MouseButton1Click:connect(Click)

0
Didn't work Bulvyte 388 — 8y
0
the function works. you have to be pointing to the sound and the sound has to be playing, do you have another script that is playing the sound?. try placing the sound in player.PlayerGui and use the code i just edited above. johnnygadget 50 — 8y
0
local function Click() ?? remove the local m8 Operation_Meme 890 — 8y
0
why? it works. i like to keep everything local. what's the use of making it global? johnnygadget 50 — 8y

Answer this question