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
12Strings
(12Strings)
November 14, 2021, 3:10am
2
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’
12Strings
(12Strings)
November 14, 2021, 3:12am
4
Run the codes inside local script.
why though? what’s the difference?
12Strings
(12Strings)
November 14, 2021, 3:16am
6
Because you can’t get player’s mouse in server-side.
im not getting errors but its not working
CLS0211
(CLS0211)
November 14, 2021, 3:26am
8
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)
CLS0211
(CLS0211)
November 14, 2021, 3:30am
10
Sorry, i’m not good with instance.new, so I can’t really help you there
batteryday
(batteryday)
November 14, 2021, 3:31am
11
KrimsonWoIf:
script:
`local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
Mouse.Button1Down:connect(function()
if Mouse.Target.Name == "TextLabel" then
print('yea')
end`
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?
12Strings
(12Strings)
November 14, 2021, 3:35am
13
Read the developer API to gain more informations.
batteryday
(batteryday)
November 14, 2021, 3:36am
14
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.
batteryday
(batteryday)
November 14, 2021, 3:38am
16
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
batteryday
(batteryday)
November 14, 2021, 3:43am
18
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
batteryday
(batteryday)
November 14, 2021, 3:47am
20
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