I'm a little confused. pretty sure I can't use a function in a if statement like I did but I don't know the alternative. basically just trying to print "done" if the part is hovered over by the mouse and clicked. any help would be appreciated
01 | local player = game.Players.LocalPlayer |
02 | local mouse = player:GetMouse() |
03 |
04 | local function clicked() |
05 | mouse.Button 1 Down:connect( function () |
06 |
07 | end ) |
08 | end |
09 |
10 |
11 | mouse.move:connect( function () |
12 |
13 | if mouse.Target = = game.Workspace.Part and clicked() then |
14 | print ( "done" ) |
15 |
16 | end |
17 |
18 | end ) |
There are many ways to achieve this but the easiest would be by adding a clickdetector
to the part
and then using the MouseClick
event
example:
1 | local part = workspace.Part |
2 | local ClickDetector = Instance.new( "ClickDetector" ) -- u can add the clickdetector manually into workspace or using script, your choice |
3 | ClickDetector.Parent = part |
4 |
5 | ClickDetector.MouseClick:Connect( function () |
6 | print ( "done" ) |
7 | end ) |
see this article over clickdetector
and u can use functions in if statements