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

Middle Mouse Button Isn't Working Like I Wan't It To?

Asked by 6 years ago
Edited 6 years ago

Hey, I've been trying to get this to work for hours, I've tried googling but there wasn't much help there. I'm trying to make it run a function when I press the mouse WHEEL button, however, the script isn't working properly, instead of it working when I press the MOUSE WHEEL BUTTON, it works with EVERY button on my keyboard.

Here is the code I'm working with so far, 0 errors just doesn't work like I wan't it to.

local UIS = game:GetService("UserInputService")


function randomfunction()
print("test")
end


UIS.InputBegan:connect(function()
randomfunction()
end)

Can someone teach me how to use the Mouse Wheel Button in a script?

Thanks

~Rafael

1 answer

Log in to vote
0
Answered by 6 years ago
local UIS = game:GetService("UserInputService")


function randomfunction()
print("test")
end


UIS.InputBegan:connect(function()
    If input.UserInputType == 
    Enum.UserInputType.MouseButton3 then -- Notice
        randomfunction()
    end
end)

You forgot to add a conditional statement to make sure that only input of the MouseButton3 type (middle wheel) triggers the function.

Hope this helped.

1
Thank you so much dude! T0tallyN0tATr0ll -2 — 6y
Ad

Answer this question