Hi guys! I'm new to the roblox studio and a really newbie there. I'm trying to make a FPS game so OFC we need to script about the scroll switch. But I don't know. The youtubes videos are outdated. Is there somebody know how to? Please tell me the script and where to put it. Thanks! Btw the game is already published. Game : https://www.roblox.com/games/4498440039/Countrys-calling Please try it! It helps alot!
Keep in mind: only do this for first person games because with third person games, you use the scroll wheel to move camera in/out.
You can can use the Mouse.WheelForward
and Mouse.WheelBackward
events to get which direction the scroll wheel is moving.
I'll make a short example of how to set this up so it moves through 10 slots (not actually though it's just a variable)
01 | local currentSlot = 1 |
02 |
03 | local Players = game:GetService( "Players" ) |
04 | local Mouse = Players.LocalPlayer:GetMouse() |
05 |
06 | Mouse.WheelForward:Connect( |
07 | function () |
08 | if currentSlot < 10 then |
09 | currentSlot = currentSlot + 1 |
10 | else |
11 | currentSlot = 1 |
12 | end |
13 | end |
14 | ) |
15 |
I tried this a lot of tiems i have a script that does work, but it chances not to the next number weapon in the hotbar, but to a random one.
https://scriptinghelpers.org/questions/37016/detecting-the-direction-the-mouse-wheel-is-moving