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.
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)
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!