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
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)
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!
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)