Trying to detect RMB input, LMB input is detected when I press the RMB.
On below image, I pressed the RMB 4 times. It outputs as LMB (MB1)
My goal for this post is to:
A. Figure out if I am doing something wrong.
B. Figure out if this is a roblox bug.
C. Hardware error?
If you have any information on why this is happening, please help out!
Thanks!
Code Below:
-- Ui toggle & mode enable / disable
buildModeEnabled = true
nonInputs_folder:WaitForChild("CoreGui").Value.Enabled = buildModeEnabled
-- Get mouse inputs while build mode is enabled
local mouse = local_plr:GetMouse()
-- Editing objects input
local startClick = nil
local allowEdit = nil
local connected_Buildmode1 = UIS.InputBegan:Connect(function(input)
startClick = os.clock()
while allowEdit == nil do
task.wait()
end
if allowEdit == true then
allowEdit = nil
elseif allowEdit == false then
allowEdit = nil
return
end
warn(input.UserInputType == Enum.UserInputType.MouseButton2, input.UserInputType)
if input.UserInputType == Enum.UserInputType.MouseButton2 then -- Editing / Selecting parts
local hit = mouse.Target
if hit then
if hit.Parent.Parent.Name == "Objects" then
-- Below put functions for UI input and keybind input for editing objects
local function select_new_object()
if old_box then old_box:Destroy() end
local box = Instance.new("SelectionBox")
box.Adornee = hit
box.Parent = hit
box.Color3 = Color3.fromRGB(0, 170, 255)
nonInputs_folder:WaitForChild("EditMenu").Value.Enabled = true
old_box = box
end
select_new_object()
end
end
end
end)
-- why does below exist?
-- no event for click, so I will detect a click myself (click would be mouse down then up right after)
local connected_Buildmode2 = UIS.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
local delta = os.clock() - startClick
if delta < 0.5 then
allowEdit = true
else
allowEdit = false
end
end
end)
I can’t say for sure as I’ve never had this issue, so I can only say it may just be the hardware. Try maybe using another mouse, or even getting another player to try the same script. If it still occurs, prob a bug.
This is a cut down version of your script focused on just showing the right click.
This is tested and will print: Left mouse click detected! If this isn’t working for you, it’s not the script. It has to be something else …
Script
local UIS = game:GetService("UserInputService")
local mouse = game.Players.LocalPlayer:GetMouse()
local startClick = nil
local allowEdit = nil
local connected_Buildmode1 = UIS.InputBegan:Connect(function(input)
startClick = os.clock()
while allowEdit == nil do
task.wait()
end
if allowEdit == true then
allowEdit = nil
elseif allowEdit == false then
allowEdit = nil
return
end
if input.UserInputType == Enum.UserInputType.MouseButton2 then
print("Left mouse click detected!")
end
end)
local connected_Buildmode2 = UIS.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
local delta = os.clock() - startClick
allowEdit = delta < 0.5
end
end)
Re-ordered following code and it started working correctly.
local connected_Buildmode1 = UIS.InputBegan:Connect(function(input)
if input.UserInputType ~= Enum.UserInputType.MouseButton2 then
return
end
startClick = os.clock()
while allowEdit == nil do
task.wait()
end
if allowEdit == true then
allowEdit = nil
elseif allowEdit == false then
allowEdit = nil
return
end
local mouse = local_plr:GetMouse()
local instance = mouse.Target
if instance then
if instance.Parent.Parent.Name == "Objects" then
if old_box then old_box:Destroy() end
local box = Instance.new("SelectionBox")
box.Color3 = Color3.fromRGB(0, 170, 255)
box.Adornee = instance
box.Parent = instance
old_box = box
end
end
end)