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

I need help when I scroll a mouse, to do a code, any idea? [closed]

Asked by 4 years ago

Can someone help me if I scroll a mouse forward, it does the code, but when I scroll mouse back, then it does another type of code. Any ideas, please?

0
t o d o a c o d e bhqpping 80 — 4y
0
for example, if you scroll, then it prints something iCROTony -1 — 4y

Closed as Not Constructive by Gameplayer365247v2, User#23252, and xPolarium

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
2
Answered by 4 years ago

You can achieve this with UserInputService. Here's an example.

UserInputService has an event called InputChanged that also fires when the mouse wheel is scrolled.

local InputService = game:GetService("UserInputService")

local Forward = function()
    print("The mouse was scrolled forward!")
    -- Do a code
end

local Backward = function()
    print("The mouse was scrolled backward!")
    -- Do a code
end

InputService.InputChanged:Connect(function(Input)
    if Input.UserInputType == Enum.UserInputType.MouseWheel then
        local Direction = Input.Position.Z
        if Direction == 1 then
            Forward()
        elseif Direction == -1 then
            Backward()
        end
    end
end)
Ad