This might need to be in code review, but I am working on a script, and it is late where I am. And you know when you have been scripting for 9 hours and you just forget everything, that is where I am at.
Anyway I want to know if I am doing my custom toolbar script correctly. I am working on adding keybinds to it.
Everything else works, but I want to know if I am doing the key binds correctly
local player = game.Players.LocalPlayer
local character = player.Character
local uis = game:GetService("UserInputService")
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
local function Scan(location)
for i,v in pairs(location:GetChildren()) do
if v:IsA("Tool") then
table.insert(items, v)
end
end
end
local function Update()
for i,v in pairs(frames) do
v:Destroy()
end
for i,v in pairs(items) do
local sample = script.Sample:Clone()
sample.Name = v.Name
sample.Parent = script.Parent.Holder
sample.Image = v.TextureId
sample.LayoutOrder = i
table.insert(frames, sample)
sample.MouseButton1Click:Connect(function()
if equipped == nil or equipped ~= v then
equipped = v
character.Humanoid:UnequipTools()
wait()
character.Humanoid:EquipTool(v)
else
equipped = nil
character.Humanoid:UnequipTools()
end
end)
if i == 1 then
KeyCode = Enum.KeyCode.One
elseif i == 2 then
KeyCode = Enum.KeyCode.Two
elseif i == 3 then
KeyCode = Enum.KeyCode.Three
end
uis.InputBegan:Connect(function(input, gameEventThing)
if input.KeyCode == KeyCode then
-- Equip tool script here
end
end)
end
end
local function BackpackChanged()
items = {}
Scan(character)
Scan(player.Backpack)
Update()
end
BackpackChanged()
player.Backpack.ChildAdded:Connect(BackpackChanged)
player.Backpack.ChildRemoved:Connect(BackpackChanged)
character.ChildAdded:Connect(BackpackChanged)
character.ChildRemoved:Connect(BackpackChanged)