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

How to make a script of weapon switch using scroll?

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!

3 comments

0
0

yep like that

0

Okay, this took me ~1 hr 30 min. You will need to use ContextActionService. I don't advise using Mouse.WheelForward or Mouse.WheelBackward, as it can cause errors and it should not be used in new work.

3 answers

✓ Accepted answer

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)

local currentSlot = 1

local Players = game:GetService("Players")
local Mouse = Players.LocalPlayer:GetMouse()

Mouse.WheelForward:Connect(
    function()
        if currentSlot < 10 then
            currentSlot = currentSlot + 1
        else
            currentSlot = 1
        end
    end
)

Mouse.WheelBackwards:Connect(
    function()
        if currentSlot > 1 then
            currentSlot = currentSlot - 1
        else
            currentSlot = 10
        end
    end
)

3 comments

0

you should instead be using the mod operator. currentSlot = currentSlot % max + 1

0

Um do you know where to put like the local script or just the script and Where to make the script like the serverstorage or serverscript service. Im a bit dumb here.

0

localscript inside of weapon

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.

2 comments

0

But do you know where to put the script like : serverscriptservice or serverstorage?

0

scs

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