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

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

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

✓ Accepted answer

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)

5 comments

0

rlly you copy pasted

0

I truly didn't I guess we just had the same idea.

0

ok but that third guy is REALLY copying

0

what lol

0

Umm.. I think US two had the same idea but really nobody copied your answer. There's just no reason to.

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!

2 comments

0

It's not copy and paste if the answer given is actually suitable.

0

You wrote the SAME thing as the 2nd guy in the script.

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)

1 comment

0

GUYS PLEASE IM NOT AN COPY PASTING OBJECT!! STOP COPY PASTING MY ANSWER!!!!

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