Making Play Button Work

Heya Guys!

I’m creating my own play button and tried to script it but it only just comes up with a red line and when I finished off the function message, the end) didn’t appear so I don’t know what to do. Please answer if you know what is wrong with the script! Thanks!! image|690x388

3 Likes

You have to write “end)” on the line beneath it.

2 Likes

Screen Shot 2563-05-16 at 20.55.07

script.Parent.Button.MouseButton1Click:Connect(function()
     print("Clicked")
end)

OutPut: --> "Clicked"

This is the basic function of clicking on gui button.

1 Like

Ok, where in the script does that go?

1 Like

In future, instead of uploading an image, you should just use a code block. It makes it easier for people to read the code you’ve written!

EG:

local Screen = script.Parent.Screen
locla Playbutton = Screen.Play

PlayButton.MouseButton1Click:Connect(function()
    print("hi")
end) 

Just as a sidenote, Activated isn’t an event of any GUI button. You should use the MouseButton1Click event to detect clicks on GUI buttons!

EDIT: I found out that Activated is actually a valid event. I’ve never used it before, but I would still recommend using MouseButton1Click!

Hope you found this helpful!

1 Like

Ooooo, thank you so much!
Let me try it now.

1 Like
local Screen = script.Parent.Screen
local PlayButton = Screen.Play

PlayButton.MouseButton1Down:Connect(function()
    print("button was pressed or clicked")
end) 

MouseButton1Down works for every platform! MouseButton1Click only works for computer!

2 Likes

still coming up with the red line image

1 Like

You’ve spelt function as “funtion”!

1 Like

Woops, let me try again. Sorry bout this.//

1 Like

I don’t think that’s true. I use it for all my GUI buttons, and I’ve had no complaints from mobile users that it doesn’t work.

1 Like

Guys, it still dosen’t work. I don’t know what I’m doing wrong

1 Like

MouseButton1Click is indeed compatible with all platforms, and is perfectly fine to use.

@galaxy63197 and the solution is just to place end) at the end of your function; however, if you don’t put anything inside of the function, nothing is going to happen. You need to give the script some instructions.

MouseButton1Down does, its true i’ve experimented with it before and i used mousebutton1click gui and went on a mobile device and pressed the gui it didnt do anything. MouseButton1Down did the job for me. Maybe MouseButton1Click works with other platforms now? Because i tested this a year ago.

@galaxy63197 just try out my code, it works

Ok, I’ll try that. See if it works.

Do like this:

local Screen = script.Parent.Screen
local Playbutton = script.Play or Script.Parent.Screen.Play

PlayButton.MouseButton1Click:Connect(function()
print(“this is the correct way lol”)
end)

If you don’t close the function with and end, the script editor will continue to show the red line, which in your case, is likely signaling a syntax error.

ButtonName.MouseButton1Click:Connect(function()
--Write code that you want to be executed when the button is clicked inside this function.
end)

Still dosen’t work For some reason. Here image

I think write “Connect” with small letters, idk I am not on studio right now and I cant tell what to do xd

Is PlayButton definetly a GuiButton object?

Do you have the output window open?