|
So, I'm trying to add music at the start of the game and end it when I pressed a GUI button. Help? |
|
|
local button = --fill this in
local music = --fill this in
button.MouseButton1Click:connect(function()
music:Stop()
end)
|
|
|
(whatever var you stored the sound in):Stop() when you click the gui button |
|
|
Wait do I put it in workspace as a local script or a normal script? |
|
|
local button = workspace.IntroGui.MainGameGUI.Play
local music = 151489391
button.MouseButton1Click:connect(function()
music:Stop()
end)
(This was in workspace in a normal script) |
|
JoshRBXJoin Date: 2012-05-19 Post Count: 8778 |
Is your intro GUI in the Workspace? |
|
|
|
local button = workspace.IntroGui.Intro.MainGameGUI.Play
local music = 151489391
button.MouseButton1Click:connect(function()
music:Stop()
end)
I fixed the old one because it wasn't going through to the right place.
But it still doesn't work.
|
|
JoshRBXJoin Date: 2012-05-19 Post Count: 8778 |
local button = workspace.IntroGui.Intro.MainGameGUI:Play() |
|
|
local button = workspace.IntroGui.Intro.MainGameGUI:Play()
local music = 151489391
button.MouseButton1Click:connect(function()
music:Stop()
end)
It still doesn't work ;-; |
|
|
|
well look at the logic bro
you're trying to call stop on an asset id
that shouldn't work in the first play
stop the sound's location in workspace
Formerly xXTheRobotXx, add 13,349 posts |
|
|
"workspace"
or whatever the path is
Formerly xXTheRobotXx, add 13,349 posts |
|
|
You can't set an action as a variable, that is why it is not firing..
Also, you need to define the Sound asset as well as the SoundId. You also need to put the GUI into the PlayerGUI, unless if this is a Surface/BillboardGUI.
FIX:
local button = workspace.IntroGui.Intro.MainGameGUI -- If this is a ScreenGUI, then copy this script into a LocalScript inside StarterPlayerScripts, as well as put the GUI into StarterGUI and define the player.
local music = Instance.new("Sound", workspace)
local music.SoundId = rbxassetid://[ID here]
music:Play()
button.MouseButton1Click:connect(function()
music:Stop()
end)
Sidenote: Try to give your variables more meaningful names..these are too generic.
Expect nothing, to expect everything |
|
|
Wait why does it have to be in the playerGUI.
It's part of the script where it does it for me.
local legui = script.Intro:Clone()
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:wait()
legui:Clone().Parent = player.PlayerGui
end)
(I didn't want too many GUIs on my screen) |
|
|