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
9 years ago
01local player = game.Players.LocalPlayer
02local sound = player.Aviici
03 
04function Click()
05 
06    player.sound.Volume = 0
07 
08end
09function Click()
10 
11    player.sound.Volume = 0.25
12 
13end
14 
15 
16script.Parent.MouseButton1Down:connect(Click)
17script.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 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

At line 1-2:

1local player = game.Players.LocalPlayer.Aviici
2local 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

1local x = script.Parent
2local y = x.Parent
3 
4   x.y.BrickColor = BrickColor.new("Really black") -- WRONG
5--/\/\
6--That CANNOT happen
7 
8y.BrickColor = BrickColor.new("Really black") -- RIGHT

So your script would be:

01local player = game.Players.LocalPlayer
02local sound = player.Aviici
03 
04function Click()
05 
06    sound.Volume = 0
07 
08end
09function Click()
10 
11    sound.Volume = 0.25
12 
13end
14 
15 
16script.Parent.MouseButton1Down:connect(Click)
17script.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 — 9y
0
Is this in a local script. If not, then you can't use LocalPlayer DragonOfWar900 397 — 9y
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 — 9y
Ad
Log in to vote
0
Answered by 9 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...

01local player = game.Players.LocalPlayer
02local sound = player.PlayerGui:WaitForChild("Aviici")
03sound:Play()
04 
05local function Click()
06    if sound.Volume == 0 then
07        sound.Volume = 0.25
08    else
09        sound.Volume = 0
10    end
11end
12 
13 
14 
15script.Parent.MouseButton1Click:connect(Click)
0
Didn't work Bulvyte 388 — 9y
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 — 9y
0
local function Click() ?? remove the local m8 Operation_Meme 890 — 9y
0
why? it works. i like to keep everything local. what's the use of making it global? johnnygadget 50 — 9y

Answer this question