I made a script that punches when you press q, but i want to know how i can make it a click to punch script instead.
local UserInputService = game:GetService("UserInputService") local ReplicatedStorage = game:GetService("ReplicatedStorage") local punchEvent = ReplicatedStorage:WaitForChild("PunchEvent") local ready = true local function punch(inputObject, gameProcessed) if inputObject.KeyCode == Enum.KeyCode.Q and ready then punchEvent:FireServer() ready = false wait(0.5) ready = true end end UserInputService.InputBegan:Connect(punch)
You would find the player's mouse using :GetMouse()
. Then, you would use a click function through Button1Down
.
Local Script:
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local ReplicatedStorage = game:GetService("ReplicatedStorage") local punchEvent = ReplicatedStorage:WaitForChild("PunchEvent") local ready = true local function punch() if ready then punchEvent:FireServer() ready = false wait(0.5) ready = true end end mouse.Button1Down:Connect(punch)
All you would have to do is change line 8, you are currently checking if the input is Q.
Check if the UserInputType == Enum.UserInputType.MouseButton1
because MouseButton1 is left click.
local function punch(inputObject, gameProcessed) if inputObject.UserInputType == Enum.UserInputType.MouseButton1 and ready then -- rest of code
EDIT:
I'd recommend going through with InfernoExeuctioner's idea, using the mouse would eliminate your need for using UserInputService at all.