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!