Mousebutton1down help

error: Workspace.Script:6: Expected ‘end’ (to close ‘function’ at line 3), got ; did you forget to close ‘then’ at line 4?

script:
`local player = game.Players.LocalPlayer

local Mouse = player:GetMouse()

Mouse.Button1Down:connect(function()

if Mouse.Target.Name == "TextLabel" then

	print('yea')

end`

objective: when player clicks, print ‘Yea’
note: please give me working answers

Mouse.Button1Down:connect(function()
	if Mouse.Target.Name == "TextLabel" then
		print('yea')
	end
end) -- You forgot the bracket end

Workspace.Script:2: attempt to index nil with ‘GetMouse’

Run the codes inside local script.

why though? what’s the difference?

Because you can’t get player’s mouse in server-side.

im not getting errors but its not working

Not sure if this will help in any but here:

script.Parent.Mousebutton1click:Connect(function()
      print('yea')
end)

Also, is it local script? That may be the issue.

the point is if a part is named click it will print
(im try to make a script on a instance .new)

Sorry, i’m not good with instance.new, so I can’t really help you there :frowning:

Please format the code properly so we can read it

ah good to know, I was going to post Beethoven’s 5th symphony.


These are the problems I noticed

  • There is a missing end
  • Code must be in localscript
  • mouse.Target returns a BasePart not a GUIObject

that was a super passive agressive answer to my problems, wow.
what should i do for gui?

Read the developer API to gain more informations.

For a GUIObject you have to use TextButton and then use MouseButton1Click

If you really don’t want to use a TextButton you can track the mouse’s movement and compare the location of the mouse with the location of a TextLabel and then run the code when the player clicks using UserInputService

write a scripted example please. :slightly_smiling_face:

local TextButton = pathToTextButton

TextButton.MouseButton1Click:Connect(function()
     print("yea")
end)

GuiButton API

1 Like

thats wrong. pathToTextButton doesn’t exist
is it suppose to be script.parent

you need to make it exist, I thought I made it clear by writing “path”

if that’s the path (if the localscript is parented to a TextButton then script.Parent is the path)

1 Like

i see thanks. good stuff and thanks

1 Like

no problem!

also I realized you used MouseButton1Down and I used MouseButton1Click in my example. You can use either one. MouseButton1Click just means a full click (down then up)

  • MouseButton1Down = mouse down
  • MouseButton1Up = mouse up
  • MouseButton1Click = mouse down then up