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

How do i make a press q to switch between tool in slot 1 to tool in slot 2 and so forth?

Asked by 3 years ago

its a localScript i put it in starterCharacterScripts because if i put it in StarterPlayerScripts when i die it wont work

local UserInputService =  game:GetService('UserInputService')
local debounce = false
UserInputService.InputBegan:Connect(function(input,gameProccesedEvent)
    if input.KeyCode == Enum.KeyCode.Q and debounce == false then
        print("Q")

    end
end)

i made some modifications to the Local Script and it broke so i had to make a new one

0
i forgot some parts of my script because i did this aweek ago so this is what is left bruce_matthew 4 — 3y
0
noone answer this bruce_matthew 4 — 3y
0
Is this using the default Roblox backpack? User#30567 0 — 3y
0
yes bruce_matthew 4 — 3y

1 answer

Log in to vote
1
Answered by
imKirda 4491 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

For the slot system you can make value that will increase every time you press the Q button, and if the slot is higher than your max then reset it back to default.

local UserInputService =  game:GetService('UserInputService')
local debounce = false

local slot = 1
local maxSlots = 10

UserInputService.InputBegan:Connect(function(input,gameProccesedEvent)
    if input.KeyCode == Enum.KeyCode.Q and debounce == false then
        print(slot)
        slot = (slot % maxSlots) + 1
    end
end)

Basically the line with adding slot what it does:

It adds +1 to the slot, and it uses the modulus operator on the number, the modulus returns how much is left when divided by the number so: 10 % 2 = 0 left but 10 % 4 = 2, because 4 can fit 2 times into 10 but 4*2 = 8 so 10 - 8 is 2 which is the number it returns.

about %

EDIT: Here is how to split it into 2 lines

UserInputService.InputBegan:Connect(function(input,gameProccesedEvent)
    if input.KeyCode == Enum.KeyCode.Q and debounce == false then
        print(slot)
        slot = (slot + 1)
        ...
        slot = slot%maxSlots
    end
end)
Ad

Answer this question