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

How do I detect if the player is holding down the RightMouseButton?

Hello! I have a game that allows the player to shine a flashlight by holding down RMB(RightMouseButton) But I can't seem to find the correct use for it in UIS. Here's the script that I have: (its local)

local uis = game:GetService("UserInputService")

local holdingRMB = false

uis.InputBegan:Connect(function(inputObject)
	if inputObject.KeyCode == Enum.KeyCode.??? then
		holdingRMB = true
	end
end)

Any working answer is appreciated.

1 answer

✓ Accepted answer
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local holdingRMB = false

mouse.Button2Down:Connect(function()
	holdingRMB = true
end)

mouse.Button2Up:Connect(function()
	holdingRMB = false
end)

while true do
	if holdingRMB then
		--Path to flashlights light = true
	else
		--Path to flashlights light = false
	end
	wait()
end

2 comments

0

Thanks! But don't forget to always put your code in code blocks.

0

sorry. i edited it in code blocks

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