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

help with music gui's? [Half Solved]

Asked by 8 years ago

ok so im making a gui that when you click it music plays. theres going to be a lot of these gui's. the thing is the music wont play. heres the code:

local button = script.Parent
local sound = button:WaitForChild('Sound')

sound:Play()

local function onButtonClick()
    if sound.IsPlaying then
        sound:Stop()
    else
        sound:Play

    end

end


button.MouseButton1Click:connect(onButtonClick)

ok so the script the other guy gave me work...but now when ever i enter the game the music plays without me clicking the gui.

2 answers

Log in to vote
0
Answered by 8 years ago

You forgot the parenthesis around 'Play'.

local button = script.Parent
local sound = button:WaitForChild('Sound')

sound:Play()

local function onButtonClick()
    if sound.IsPlaying then
        sound:Stop()
    else
        sound:Play()

    end

end


button.MouseButton1Click:connect(onButtonClick)
0
That too XD User#11440 120 — 8y
0
What parenthesis USArmyRanger2003 0 — 8y
0
only one prob the music plays at the begining of the game USArmyRanger2003 0 — 8y
0
on line ten you didn't put the () after :Play :P User#11440 120 — 8y
0
ok XD USArmyRanger2003 0 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

I think one of your problems is where the sound is located. To make the player who pressed the button hear the sound and no one else, you would insert the sound into the player. You should be using a local script as well. You would then get the player by using,game.Players.LocalPlayer.Sound:Play(). Also you don't need thesound:Play() on line 4. Since you're going to be adding a lot of sounds to your music GUI you might want to insert a sound folder. Just make a folder in workspace and fill it up with the sounds you want. Then when a player joins put the folder into the player,

game.Players.PlayerAdded:connect(function(plr)--Returns player
   local SoundFolderClone = game.Workspace.SoundFolder:Clone() --Clones folder
   SoundFolderClone.Parent = plr --Puts folder in player
end

If my memory serves me right this should work. If not use :GetChildren() from the folder before cloning it. I hope this helped! Good luck!

0
i am using a local script USArmyRanger2003 0 — 8y

Answer this question