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

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

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

4 comments

0

i forgot some parts of my script because i did this aweek ago so this is what is left

0

noone answer this

0

Is this using the default Roblox backpack?

0

yes

1 answer

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)

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