Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does UserInputService:IsMousePressed not work?

Asked by
adcd433 12
3 years ago

This is in local script.

local Tool = script.Parent local UserInputService = game:GetService("UserInputService") Tool.Equipped:Connect(function() if UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)== true then print("yay") end end)

i know this might be noob question but pls help

0
Code block Pupppy44 671 — 3y
0
what does code block mean? adcd433 12 — 3y
0
There should be the lua logo when you're typing your question, you can use that to format your code to Lua. Anyways you can check my answer and see if it works Pupppy44 671 — 3y

1 answer

Log in to vote
0
Answered by
Pupppy44 671 Moderation Voter
3 years ago
Edited 3 years ago

You'll need to use InputBegan. Example:

local UIS = game:GetService("UserInputService") -- Getting the service

function Began(Input) -- Function, input is the key typed
if Input.UserInputType == Enum.UserInputType.MouseButton1 then -- Checking if the key pressed was MouseButton1 aka. left click
print("Clicked!")
end -- Ends if statement
end -- Ends function

UIS.InputBegan:Connect(Began) -- The event for InputBegan

Or, you can use Activated, which is a lot more simple.

function Clicked() -- Function
print("Clicked!") -- Prints out "Clicked!"
end -- Ends function

script.Parent.Activated:Connect(Clicked) -- The event for Activated, aka. when a player presses left click

Hope this helps!

0
Ok thx adcd433 12 — 3y
Ad

Answer this question