-Is it mouse.Button1Down
and mouse.Button1Up
, Enum.UserInputType.MouseButton1
, or tool.Activated
?
I would use UserInputService
.
To me, I feel like UserInputService is much more flexible than .Activated
or any other way you would detect a click with a tool.
Here's how to use it.
01 | -- Local script inside tool |
02 | local tool = script.Parent |
03 |
04 | local UserInputService = game:GetService( "UserInputService" ) |
05 | local enabled = false |
06 |
07 | UserInputService.InputBegan:Connect( function (input, gameProcessed) |
08 | if gameProcessed or not enabled then return end |
09 | if input.UserInputType = = Enum.UserInputType.MouseButton 1 then |
10 | -- Fire remote event |
11 | end |
12 | end ) |
13 |
14 | tool.Equipped:Connect( function () |
15 | enabled = true |
16 | end ) |
17 |
18 | tool.Unequipped:Connect( function () |
19 | enabled = false |
20 | end ) |
Server script:
1 | RemoteEvent.OnServerEvent:Connect( function (player) |
2 | -- Code |
3 | end ) |
depends on what you are trying to do
generally i would go for <mouse.Button1Down and <mouse.Button1Up>
if you want to make a gun for example then best go for the <mouse.Button1Down and <mouse.Button1Up> options
this is mostly opinion
Tool.Activated
is the easiest to use for me.
Example of use:
01 | --LocalScript inside tool |
02 |
03 | tool = script.Parent |
04 |
05 | function makeEvent() |
06 | local remoteEvent = Instance.new( "RemoteEvent" , game:GetService( "ReplicatedStorage" ) |
07 | remoteEvent.Name = PointsEvent |
08 | remoteEvent:FireServer() |
09 | end |
10 |
11 | tool.Activated:connect(makeEvent) |
12 |
13 |
14 | --ServerScript in ServerScriptService |
15 |
Hope this helps!