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

How do you make music play in a ScreenGui?

Asked by 5 years ago
Edited 5 years ago

how do you make music play in a screengui? for example, i'm making a game and i have a title screen with labels and buttons, right? and then, i want to add music that lasts until you select the button to play the game! which has it's script that works already

PLAYGAME.MouseButton1Click:Connect(function() Frame.Visible = false end)

then, i try to create the music part, but it doesn't work

01--variables--
02Sound = script.Parent.Sound
03PLAYGAME = script.Parent.PLAYGAME
04 
05--scripts--
06Sound:Play()
07Sound.Playing = true
08PLAYGAME.MouseButton1Click:connect(function()
09    Sound.Playing = false
10end)

if im doing something wrong then please tell me that would really help! thanks!

edit: the PLAYGAME button is inside of a frame inside of a ScreenGui and inside of the StarterGui folder. the Sound, i moved to the workspace

0
i'm an amateur at scripting sorry :| LinkZelda_Sage 16 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago
01--services--
02local Players = game:GetService('Players') -- This is the folder that you can see on the explorer.
03 
04--variables--
05local Player = Players.LocalPlayer -- This is you, but you can do it just in a LocalScript.
06local PlayerGui = Player:WaitForChild('PlayerGui')
07local ScreenGui = PlayerGui:WaitForChild('ScreenGui') -- Just put the name of your ScreenGui here.
08 
09local Sound = ScreenGui:WaitForChild('Sound')
10local PLAYGAME = ScreenGui:WaitForChild('PLAYGAME')
11 
12--scripts--
13Sound:Play()
14PLAYGAME.MouseButton1Click:Connect(function() -- connect is deprecated use Connect.
15    Sound.Playing = false
16end)

If you have any question put it below on commentaries.

0
Actually, he's using Playing, not isPlaying, which is a writable property masterjosue1998 116 — 5y
0
where exactly do i put the script? LinkZelda_Sage 16 — 5y
0
edited the post) LinkZelda_Sage 16 — 5y
0
Put the script in StarterPlayerScripts (This is in StarterPlayer) or directly in the ScreenGui. NiniBlackJackQc 1562 — 5y
View all comments (2 more)
0
didn't work. i edited the post of the whereabouts of my items btw LinkZelda_Sage 16 — 5y
0
That work for me, check up yours variables. NiniBlackJackQc 1562 — 5y
Ad
Log in to vote
1
Answered by 5 years ago
Edited by Ziffixture 5 years ago

Sound Objects can only operate in a physical environment, i.e workspace. If you do this via a LocalScript (assuming your code is local), the sound will only be played in your client.

So It would be something like:

01local Sound = workspace.Sound
02Sound.SoundID = "rbxassetid://SoundIdHere"
03 
04local PLAYGAME = script.Parent.PLAYGAME
05 
06Sound:Play() -- Start the music
07 
08PLAYGAME.MouseButton1Click:connect(function()
09    Sound:Stop -- It’s best to use these methods to start/stop music
10end)
0
His code can only be Local, as he is operating a GUI Object. But you’re right, by referencing the Sound Instance from workspace and playing it, it will run locally. Ziffixture 6913 — 5y
0
edited the post) LinkZelda_Sage 16 — 5y

Answer this question