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

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

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?

2 comments

0

t o d o a c o d e

0

for example, if you scroll, then it prints something

1 answer

✓ Accepted answer

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)

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