Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

help with music gui's? [Half Solved]

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

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)

5 comments

0

That too XD

0

What parenthesis

0

only one prob the music plays at the begining of the game

0

on line ten you didn't put the () after :Play :P

0

ok XD

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!

1 comment

0

i am using a local script

This discussion is preserved as it was. New answers, comments, and votes are closed.