Basically what I'm doing is I'm making some scripts for gamepads. Simple enough. But then I try to add a table/list of the things in the players backpack. So far they are two items called "HiP" and "LinkedSword". What I want to be able to do is call upon the table/list and then scroll through the tools. This would involve the user pressing DPadLeft or DPadRight and then the tool changing (I can sort of do that). Here is my script so far (I removed the table/list as it keeps breaking the darn thing):

userInputService.InputBegan:connect(function(input, processed)
	if input.UserInputType == Enum.UserInputType.Gamepad1 then
		if input.KeyCode == Enum.KeyCode.DPadRight then
			game.Players.LocalPlayer.Character.Humanoid:EquipTool(player.Backpack.HiP)
		end
	end
end)

I'll also need help with the changing of the tool, as if it were to be for example:

game.Players.LocalPlayer.Character.Humanoid:EquipTool(tools[1]) -- tools being the name of the table

then if the user pressed DPadRight then it would just change through all of the tools, as if there were, say, three tools, there would be three separate parts that say:

userInputService.InputBegan:connect(function(input, processed)
	if input.UserInputType == Enum.UserInputType.Gamepad1 then
		if input.KeyCode == Enum.KeyCode.DPadRight then
			game.Players.LocalPlayer.Character.Humanoid:EquipTool(tools[1])
		end
	end
end)

userInputService.InputBegan:connect(function(input, processed)
	if input.UserInputType == Enum.UserInputType.Gamepad1 then
		if input.KeyCode == Enum.KeyCode.DPadRight then
			game.Players.LocalPlayer.Character.Humanoid:EquipTool(tools[2])
		end
	end
end)

userInputService.InputBegan:connect(function(input, processed)
	if input.UserInputType == Enum.UserInputType.Gamepad1 then
		if input.KeyCode == Enum.KeyCode.DPadRight then
			game.Players.LocalPlayer.Character.Humanoid:EquipTool(tools[3])
		end
	end
end)

which wouldn't work. Thanks for any help.

1 comment

0

When I say the DPadRight thing wouldn't work, where it says "EquipTool(tools[1])", is there a way to make it differentiate with each button, so that it goes in order? So for when I press it the first time, it picks tool1, then the second, tool2, then the third, tool3, and then revert back to the beginning?