Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does UserInputService:IsMousePressed not work?

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

3 comments

0

Code block

0

what does code block mean?

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

1 answer

✓ Accepted answer

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!

1 comment

0

Ok thx

This discussion is preserved as it was. New answers, comments, and votes are closed.