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

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

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

✓ Accepted answer
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 comment

1

Thank you so much dude!

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