#Detect when the player is holding left mouse button?
3 messages · Page 1 of 1 (latest)
Use game:GetService("UserInputService")
Or the mouse ig.
USING USERINPUTSERVICE
local IsMouseDown = false
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, gpe)
——comment this line if you want it to detect even when its a button press.
if gpe then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
IsMouseDown = true
end
end)
UIS.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
IsMouseDown = false
end
end)
while true do
task.wait()
if IsMouseDown then
print("Pressing left mouse button!")
end
end
USING MOUSE
local IsMouseDown = false
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
IsMouseDown = true
end)
mouse.Button1Up:Connect(function()
IsMouseDown = false
end)
while true do
task.wait()
if IsMouseDown then
print("Pressing left mouse button!")
end
end