local gui = script.Parent
local container = gui.container
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local controller = require(RS.ReplicaService.ReplicaController)
local refbook = require(RS.ReferenceBook)
local sound = require(RS.Libraries.Sounds)
local players = game:GetService("Players")
local player = players.LocalPlayer
local backpack = player:WaitForChild("Backpack")
repeat wait() until refbook["LocalPlayer"]
local replica = controller.GetReplicaById(refbook["LocalPlayer"])
local equipment = replica.Data
local currentSlot
local selectedProperties = {
["BackgroundColor3"] = Color3.fromRGB(45, 38, 36),
["BorderColor3"] = Color3.fromRGB(214, 181, 96),
["BorderSizePixel"] = 4,
["ZIndex"] = 10
}
local deselectedProperties = {
["BackgroundColor3"] = Color3.fromRGB(21, 18, 17),
["BorderColor3"] = Color3.fromRGB(42, 37, 34),
["BorderSizePixel"] = 3,
["ZIndex"] = 1
}
local function setProperties(slot, selected)
local preset
slot = container[slot]
if selected then
preset = selectedProperties
selectedProperties.Size = slot.Size + UDim2.fromScale(0.2, 0.2)
else
preset = deselectedProperties
deselectedProperties.Size = slot.Size - UDim2.fromScale(0.2, 0.2)
end
for property, value in pairs(preset) do
slot[property] = value
end
end
local activeTools = {}
local numslot = {
{Enum.KeyCode.One, "Primary"},
{Enum.KeyCode.Two, "Secondary"},
{Enum.KeyCode.Three, "Pickaxe"},
{Enum.KeyCode.Four, "Item1"},
{Enum.KeyCode.Five, "Item2"},
{Enum.KeyCode.Six, "Item3"},
{Enum.KeyCode.Seven, "Item4"},
{Enum.KeyCode.Eight, "Item5"},
}
local function keytoslot(keycode)
for i, pair in pairs(numslot) do
if keycode == pair[1] then
return pair[2]
end
end
return false
end
local function equipSlot(slot)
local humanoid : Humanoid = player.Character.Humanoid
humanoid:UnequipTools()
if activeTools[slot] then
local tool : Tool = activeTools[slot]
assert(tool, "'Valid' Tool Not Found For Slot "..slot)
humanoid:EquipTool(tool)
end
end
UIS.InputBegan:Connect(function(input, ignored)
if not ignored and player.Character then
local slot = keytoslot(input.KeyCode)
local humanoid : Humanoid = player.Character.Humanoid
if slot then
sound:Play({"Generic", "click1"})
if currentSlot then
setProperties(currentSlot, false)
end
if slot == currentSlot then
currentSlot = nil
humanoid:UnequipTools()
else
setProperties(slot, true)
currentSlot = slot
equipSlot(slot)
end
elseif input.KeyCode == Enum.KeyCode.Backspace then
if currentSlot then
setProperties(currentSlot, false)
currentSlot = nil
end
end
end
end)
local function update(cat, slot)
local button : TextButton = container[slot]
if replica.Data.Equipment[cat][slot] then
activeTools[slot] = backpack:WaitForChild(slot, 4)
end
end
local function setEquipListener(cat, slot)
replica:ListenToArraySet({"Equipment", cat, slot}, function()
update(cat, slot)
end)
replica:ListenToArrayRemove({"Equipment", cat, slot}, function()
activeTools[slot] = nil
update(cat, slot)
end)
end
local equipslots = {
Weapons = {"Primary", "Secondary"},
Tools = {"Pickaxe"},
Items = {"Item1", "Item2", "Item3", "Item4", "Item5"}
}
for cat, slots in pairs(equipslots) do
for i, slot in pairs(slots) do
update(cat, slot)
setEquipListener(cat, slot)
end
end
for _, button in pairs(container:GetChildren()) do
if button:IsA("TextButton") then
button.Activated:Connect(function()
local slot
for cat, slots in pairs(equipslots) do
for _, slot2 in pairs(slots) do
if button.Name == slot2 then
if equipment[cat][slot2] then
slot = {cat, slot2}
else
sound:Play({"Generic", "error3"})
return
end
end
end
end
replica:FireServer({"Inventory", "Unequip", replica.Id, {"Inventory"}, slot})
end)
end
end
Note: The actual object is there I believe. It just doesn’t display.