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

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

Asked by
2_MMZ 1059 Moderation Voter
3 years ago
Edited 3 years ago

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

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago
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
0
Thanks! But don't forget to always put your code in code blocks. 2_MMZ 1059 — 3y
0
sorry. i edited it in code blocks Dianetter7B 176 — 3y
Ad

Answer this question