Video_2D
(Video_4D)
April 4, 2020, 1:55pm
#1
So I made my own script to make the music stop when I pressed a Gui (play button) for a start menu but it won’t work, can anybody tell me what I did wrong? Scary = the music I used btw in the script.
function onClicked(TextButton)
workspace.Parent.Scary.Playing = false
workspace.Parent.Scary.Looped = false
end
script.Parent.MouseButtonClick:connect(onClicked)
3 Likes
workspace.Parent refers to the Game
You should instead change it so it references your Sound object.
Video_2D
(Video_4D)
April 4, 2020, 1:59pm
#3
The music is in SoundService so would it be workspace.SoundService
It should be game:GetService(“SoundService”):FindFirstChild(“Scary”)
Video_2D
(Video_4D)
April 4, 2020, 2:04pm
#5
So the new script would be function onClicked(TextButton)
game:GetService(“SoundService”):FindFirstChild(“Scary”)
end
script.Parent.MouseButton1Click:Connect(onClicked)
1 Like
johanjv
(ThirdRepresentative)
April 4, 2020, 2:07pm
#6
So
for the last line of the code, it should be
script.Parent.MouseButton1Click:Connect(OnClicked)
MouseButtonClick does not exist for GUI Buttons, as far as I know.
Also use :Connect instead of :connect.
Also, that ^
No, the game:GetService(“SoundService”):FindFirstChild(“Scary”) part is the reference or ‘location’ of your Sound object.
You would replace
workspace.Parent.Scary
with
game:GetService("SoundService"):FindFirstChild("Scary")
Video_2D
(Video_4D)
April 4, 2020, 2:08pm
#8
I fixed them. Hopefully…
function onClicked(TextButton)
game:GetService(“SoundService”):FindFirstChild(“Scary”)
end
script.Parent.MouseButton1Click:Connect(onClicked)
Video_2D
(Video_4D)
April 4, 2020, 2:10pm
#9
Would I add .playing = false after game:GetService(“SoundService”)FindFirstChild(“Scary”)?
Yes, but with a capital P.
And also, try removing TextButton from function onClicked(TextButton)
?
Video_2D
(Video_4D)
April 4, 2020, 2:12pm
#11
It didn’t work. (30 charsssssssssss)
Video_2D
(Video_4D)
April 4, 2020, 2:13pm
#12
function onClicked(TextButton)
game:GetService(“SoundService”):FindFirstChild(“Scary”).Playing = false
end
script.Parent.MouseButton1Click:Connect(onClicked)
Video_2D
(Video_4D)
April 4, 2020, 2:14pm
#13
I’ll try to figure it out, but thanks for trying to help me.
Pixeluted
(Pixeluted)
April 4, 2020, 2:15pm
#14
You should do @Video_2D
function onClicked(TextButton)
workspace.Parent.Scary:Stop() -- do :Stop() no Playing = false or if you want again play it do :Play()
end
script.Parent.MouseButtonClick:connect(onClicked)
1 Like
Video_2D
(Video_4D)
April 4, 2020, 2:17pm
#15
I’ll try it. (30 charsssssssss)
Video_2D
(Video_4D)
April 4, 2020, 2:18pm
#16
Thank you, it worked. (30 char)
Video_2D
(Video_4D)
April 4, 2020, 2:19pm
#18
I did. (30 charssssssssssssssss)