Tool Equipping Help

I am following this tutorial, and I am facing an issue, I am trying to make it so tools are tied to keybinds not by name, but rather by tag, but when I press any of the keys nothing happens.

local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local plr = Players.LocalPlayer
while not plr do
	plr = Players.LocalPlayer
	task.wait(1)
end
local char = plr.Character or plr.CharacterAdded:Wait()
local human = char:WaitForChild("Humanoid")
local bck = plr:WaitForChild("Backpack")
local Primary, Secondary, Gadget

task.wait(1)

for _, tool in pairs(bck:GetChildren()) do
	if tool:IsA("Tool") then
		if tool:FindFirstChild("Tags") then
			if tool.Tags:FindFirstChild("Primary") then
				Primary = tool
			elseif tool.Tags:FindFirstChild("Secondary") then
				Secondary = tool
			elseif tool.Tags:FindFirstChild("Gadget") then
				Gadget = tool
			end
		end
	end
end

local function OnInput(input, Chat)
	if Chat then return end

	local GKC = input.KeyCode

	if GKC == Enum.KeyCode.One and Primary then
		human:EquipTool(Primary)
	elseif GKC == Enum.KeyCode.Two and Secondary then
		human:EquipTool(Secondary)
	elseif GKC == Enum.KeyCode.Three and Gadget then
		human:EquipTool(Gadget)
	end
end

UIS.InputBegan:Connect(OnInput)

Here’s also the script that hides the hotbar/inventory.

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

Help would be appreciated!

from looking at this my guess is it happens when you get the tools, how exactly do you give your items tags?

Using this:
image

Last I checked tags arent a child, so using FindFirstChild wont work.
Instead you can use CollectionService:HasTag(Instance,TagName)

1 Like

Thank you very much! It worked!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.