Trying to make a song play when a player joins, and stop playing when they click text button "Play"

Hello there.

I’m trying to make a song play when a player joins, and if they click the text button, that is labeled “play”, to fade out when they click it.

Here is my script so far:

!
Here is my startgui, along with the title gui, and the “play” text button.
Screen Shot 2020-06-20 at 5.22.54 PM!

I’m stumped, where should I go next?

3 Likes

I see that you are trying to do

ScreenGui.("Title Screen").Button

and it is giving you a red line. What you want to do is

ScreenGui["Title Screen"].Button

You should try fixing your invalid syntax, first of all.
image

2 Likes

lol i dont even know what to replace it with tho

Replace it with these: [, ] instead of these (, ).

@DarkDanny04 @DragRacer31 @posatta

How do I fix that end? And other than that, is this good?

You simply don’t need that end) there. Also, it’s :FindFirstChild, not .FindFirstChild. Actually, you can’t use MouseButton1Click in an if statement either.

The red underline means that it’s not valid syntax, so still no. You have two ends for one open block, and you don’t ever call sound1:Stop() as a function (you just reference the function without calling it).

If you hover over the red underline, it gives helpful information about what’s wrong.

2 Likes

lol what do i do
30 charssssssss

how do i call this as a function

keep in mind fellas this is my first scripting ever

Okay, to begin with, you need to call player.PlayerGui, and not just “ScreenGui.” Secondly, it is :FindFirstChild, not .FindfirstChild(). And lastly, you don’t need that if statement there at all.

game.Players.LocalPlayer.PlayerGui["Title Screen"]:FindFirstChild("Button").MouseButton1Click:Connect(function()
     welcomeSound:Stop()
end)
1 Like

Here is how your script should look like

So, move the then over to where the arrow tells you to, then remove the end) and then add () to the end of sound1:Stop, then you should be good to go.

uh

@DragRacer31 does this work better

Oh this is a server script. You will need to do the clicking from a different script that is local then

?? i have this as a basic script in the workspace. you’re saying i just change it to a local script?

Only the

game.Players.LocalPlayer.PlayerGui["Title Screen"]:FindFirstChild("Button").MouseButton1Click:Connect(function()
     welcomeSound:Stop()
end)

needs to be in a local script. Everything else can stay there. You will need to access the welcomeSound in some way, so maybe in your server script say
welcomeSound.Name = "welcomeSound"
and then in your local script define welcome sound as
welcomeSound = workspace.welcomeSound

where do i put the local script

First of all, define welcomeSound before the clicked function, and you can put the script inside of the GUI if you would like to. Oh and you need to change the name of the sound you are creating in the server script. Just do this in the server script
welcomeSound.Name = "welcomeSound"

i have no idea what im doing lol

That looks all good. You can add a “local” before welcomeSound in the local script, but it won’t affect the functionality of the script, it will just get rid of the orange underline.

Also, it doesnt matter where you put the script since it does not change how it finds the path to the Button. As long as it is in somewhere that gets cloned to the player(inside a GUI or in starterplayerscripts) it should work.