I want to bind a function to both the left and right mouse buttons using Context Action Service, but when I do this, it removes the ability to move the camera with the right mouse button. Is there any way to make a keybind while not removing other actionbinds for that key?
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, proc)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
--do code
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
--do code
end
end)
I don’t believe UIS causes core controls to be overidden.
local UserInputType = {
MouseButton1 = function()
print("left click")
end,
MouseButton2 = function()
print("right click")
end
}
game:GetService("UserInputService").InputBegan:Connect(function(Input)
pcall(UserInputType[string.match(tostring(Input.UserInputType), ".+%.(.+)")])
end)
I know there is already an answer, but I decided to do it with a table
the functions are in the table, MB1 being the left click and MB2 being the right click
you don’t have to do it this way
since you only need two functions you can just use Limited’s code up above because that works fine
1 Like