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

What is the Enum for Holding down the left mouse (UserInputService)?

Asked by 5 years ago

I am making an assault rifle that needs the mouse being held down in order to fire automatic. I'm not sure what the enumeration for holding down the left mouse.

I am not familiar with any of this input stuff but I think I'm sure that holding down the mouse can be under UserInputService. I searched the wiki and I couldn't find what I needed.

Thank you for viewing this

3 answers

Log in to vote
1
Answered by 5 years ago

With the UserInputService you can use InputBegan and InputEnded to keep track of automatic firing.

local firing = false

UserInputService.InputBegan:Connect(function(input, gameEvent)
    if not gameEvent then
        if input.UserInputType == Enum.UserInputType.MouseButton1 then
            firing = true
        end
    end
end)

UserInputService.InputEnded:Connect(function(input, gameEvent)
    if not gameEvent then
        if input.UserInputType == Enum.UserInputType.MouseButton1 then
            firing = false
        end
    end
end)
0
rlly you copy pasted TheRealPotatoChips 793 — 5y
0
I truly didn't I guess we just had the same idea. climethestair 1663 — 5y
0
ok but that third guy is REALLY copying TheRealPotatoChips 793 — 5y
0
what lol 123nabilben123 499 — 5y
0
Umm.. I think US two had the same idea but really nobody copied your answer. There's just no reason to. namespace25 594 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

I don't think there is a way to know, but there is another way to do. We can check if the player is holding the mouse with tool.Activated and tool.Deactivated to a boolvalue:

local tool = script.Parent > the script's parent is the tool
local HodingMouse = script.Parent.HoldingMouse >  you have to insert a boolvalue named "HoldingMouse" in the the tool so the script can detect automatically after the holdingmouse's value becomes true instead of doing a "while wait(.5)"

tool.Activated:Connect(function()
    HoldingMouse.Value = true
end)

tool.Activated:Connect(function()
    HoldingMouse.Value = false
end)

script.Parent.HoldingMouse.Changed:Connect(function()
    if script.Parent.HoldingMouse.Value == true then
        repeat
        > FIRES THE GUN
        wait(.5) > THE GUN HAS TO WAIT A BIT BEFORE RESHOOTING
        until script.Parent.HoldingMouse.Value == false > STOPS THE GUN WHEN THE PLAYER STOPPED HOLDING
    end
end)

I hope this helped!

0
It's not copy and paste if the answer given is actually suitable. namespace25 594 — 5y
0
You wrote the SAME thing as the 2nd guy in the script. TheRealPotatoChips 793 — 5y
Log in to vote
0
Answered by 5 years ago

There's no direct Enum for holding the mouse but there is a trick you can use to detect it.

Example

local userInputService = game:GetService("UserInputService")
local holdingMouse = fasle

userInputService.InputBegan:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        holdingMouse = true
    end
end)

userInputService.InputEnded:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        holdingMouse = false
    end
end)
0
GUYS PLEASE IM NOT AN COPY PASTING OBJECT!! STOP COPY PASTING MY ANSWER!!!! TheRealPotatoChips 793 — 5y

Answer this question