game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
local keys = {
[1] = Enum.KeyCode.One,
}
local uis = game:GetService("UserInputService")
local rs = game:GetService("ReplicatedStorage"):WaitForChild("InventoryReplicatedStorage")
local remotes = rs:WaitForChild("RemoteEvents")
local client = game.Players.LocalPlayer
local hotbar = client:WaitForChild("Hotbar")
local inventory = client:WaitForChild("Inventory")
local equipped = client:WaitForChild("Equipped")
local hotbarGui = script.Parent:WaitForChild("Hotbar"):WaitForChild("SlotsContainer")
local inventoryGui = script.Parent
local invGui = script.Parent:WaitForChild("Inventory")
invGui.Visible = false
local openInvButton = script.Parent:WaitForChild("OpenInventory")
local currentCategory = "Swords" -- Default category
local inventoryCategories = {
Swords = script.Parent:WaitForChild("InventorySwords"),
Staffs = script.Parent:WaitForChild("InventoryStaffs"),
Bows = script.Parent:WaitForChild("InventoryBows"),
Resources = script.Parent:WaitForChild("InventoryResources"),
}
-- Initial visibility setup
for _, frame in pairs(inventoryCategories) do
frame.Visible = false
end
script.Parent.Background.Visible = false
script.Parent.SwordButton.Visible = false
script.Parent.StaffButton.Visible = false
script.Parent.BowButton.Visible = false
script.Parent.ResourceButton.Visible = false
local function updateHotbar()
print("Updating Hotbar")
for slotNum, slotVal in pairs(hotbar:GetChildren()) do
local guiSlot = hotbarGui:FindFirstChild(tostring(slotNum))
if guiSlot and slotVal.Value then
guiSlot.ItemName.Visible = true
guiSlot.ItemName.Text = slotVal.Value.Name
if slotVal.Value:IsA("Tool") and string.len(slotVal.Value.TextureId or "") > 0 then
guiSlot.ItemViewer.Visible = false
guiSlot.ItemImage.Visible = true
guiSlot.ItemImage.Image = slotVal.Value.TextureId
else
guiSlot.ItemViewer.Visible = true
guiSlot.ItemImage.Visible = false
guiSlot.ItemViewer:ClearAllChildren()
local vpfModel = Instance.new("Model")
local copiedItem = slotVal.Value:Clone()
for __, desc in pairs(copiedItem:GetDescendants()) do
if desc:IsA("LocalScript") or desc:IsA("Script") then
desc:Destroy()
elseif desc:IsA("BasePart") then
desc.Parent = vpfModel
end
end
copiedItem:Destroy()
local cf, size = vpfModel:GetBoundingBox()
local primaryPart = Instance.new("Part")
primaryPart.Transparency = 1
primaryPart.CFrame = cf
primaryPart.Parent = vpfModel
vpfModel.PrimaryPart = primaryPart
vpfModel:PivotTo(CFrame.new(Vector3.new(0, 0, 0), Vector3.new(0, math.rad(90), math.rad(90))))
local itemPivot = vpfModel:GetPivot()
local itemSize = vpfModel:GetExtentsSize()
local vpfCam = Instance.new("Camera")
vpfCam.CFrame = CFrame.new(itemPivot.Position + (Vector3.one * itemSize * 0.5), itemPivot.Position)
guiSlot.ItemViewer.CurrentCamera = vpfCam
vpfCam.Parent = guiSlot.ItemViewer
vpfModel.Parent = guiSlot.ItemViewer
end
else
if guiSlot then
guiSlot.ItemName.Visible = false
guiSlot.ItemImage.Visible = false
guiSlot.ItemViewer.Visible = false
end
end
end
end
local function updateInventory(category)
print("Updating Inventory for category:", category)
local categoryFolder = inventory:FindFirstChild(category)
if not categoryFolder then
print("Category folder not found for category:", category)
return
end
for _, invItem in pairs(inventoryCategories[category].InventoryScroller:GetChildren()) do
if invItem:IsA(script.InventoryItem.ClassName) then
invItem:Destroy()
end
end
for _, itemVal in pairs(categoryFolder:GetChildren()) do
local item = itemVal
local newItem = script.InventoryItem:Clone()
newItem.ItemName.Text = item.Name
if item:IsA("Tool") and string.len(item.TextureId or "") > 0 then
newItem.ItemViewer.Visible = false
newItem.ItemImage.Image = item.TextureId
else
newItem.ItemImage.Visible = false
newItem.ItemViewer:ClearAllChildren()
local vpfModel = Instance.new("Model")
local copiedItem = item:Clone()
for __, desc in pairs(copiedItem:GetDescendants()) do
if desc:IsA("LocalScript") or desc:IsA("Script") then
desc:Destroy()
elseif desc:IsA("BasePart") then
desc.Parent = vpfModel
end
end
copiedItem:Destroy()
local cf, size = vpfModel:GetBoundingBox()
local primaryPart = Instance.new("Part")
primaryPart.Transparency = 1
primaryPart.CFrame = cf
primaryPart.Parent = vpfModel
vpfModel.PrimaryPart = primaryPart
vpfModel:PivotTo(CFrame.new(Vector3.new(0, 0, 0), Vector3.new(0, math.rad(90), math.rad(90))))
local itemPivot = vpfModel:GetPivot()
local itemSize = vpfModel:GetExtentsSize()
local vpfCam = Instance.new("Camera")
vpfCam.CFrame = CFrame.new(itemPivot.Position + (Vector3.one * itemSize * 0.5), itemPivot.Position)
newItem.ItemViewer.CurrentCamera = vpfCam
vpfCam.Parent = newItem.ItemViewer
vpfModel.Parent = newItem.ItemViewer
end
newItem.MouseButton1Click:Connect(function()
remotes.ToHotbar:FireServer(item)
end)
newItem.MouseButton2Click:Connect(function()
if equipped.Value ~= item then
remotes.ToInventory:FireServer(item)
end
end)
newItem.Parent = inventoryCategories[category].InventoryScroller
end
end
local function findSelectedSlot()
print("Finding selected slot")
for slotNum, slotVal in pairs(hotbar:GetChildren()) do
local guiSlot = hotbarGui:FindFirstChild(tostring(slotNum))
if slotVal.Value and slotVal.Value == equipped.Value then
guiSlot.ImageColor3 = Color3.fromRGB(255, 255, 255)
else
guiSlot.ImageColor3 = Color3.fromRGB(218, 218, 218)
end
end
end
for slotNum, slotVal in pairs(hotbar:GetChildren()) do
local newSlot = script:WaitForChild("HotbarItem"):Clone()
newSlot.Name = slotNum
if keys[slotNum].Value >= 48 and keys[slotNum].Value <= 57 then
newSlot.NumberKey.Text = keys[slotNum].Value - 48
else
newSlot.NumberKey.Text = string.split(tostring(keys[slotNum]), ".")[3]
end
if slotVal.Value then
newSlot.ItemName.Text = slotVal.Value.Name
if slotVal.Value:IsA("Tool") and string.len(slotVal.Value.TextureId or "") > 0 then
newSlot.ItemViewer.Visible = false
newSlot.ItemImage.Image = slotVal.Value.TextureId
else
newSlot.ItemImage.Visible = false
newSlot.ItemViewer:ClearAllChildren()
local vpfModel = Instance.new("Model")
local copiedItem = slotVal.Value:Clone()
for __, desc in pairs(copiedItem:GetDescendants()) do
if desc:IsA("LocalScript") or desc:IsA("Script") then
desc:Destroy()
elseif desc:IsA("BasePart") then
desc.Parent = vpfModel
end
end
copiedItem:Destroy()
local cf, size = vpfModel:GetBoundingBox()
local primaryPart = Instance.new("Part")
primaryPart.Transparency = 1
primaryPart.CFrame = cf
primaryPart.Parent = vpfModel
vpfModel.PrimaryPart = primaryPart
vpfModel:PivotTo(CFrame.new(Vector3.new(0, 0, 0), Vector3.new(0, math.rad(90), math.rad(90))))
local itemPivot = vpfModel:GetPivot()
local itemSize = vpfModel:GetExtentsSize()
local vpfCam = Instance.new("Camera")
vpfCam.CFrame = CFrame.new(itemPivot.Position + (Vector3.one * itemSize * 0.5), itemPivot.Position)
newSlot.ItemViewer.CurrentCamera = vpfCam
vpfCam.Parent = newSlot.ItemViewer
vpfModel.Parent = newSlot.ItemViewer
end
else
newSlot.ItemName.Visible = false
newSlot.ItemImage.Visible = false
newSlot.ItemViewer.Visible = false
end
newSlot.MouseButton1Click:Connect(function()
local item = slotVal.Value
remotes.Equip:FireServer(item)
end)
newSlot.MouseButton2Click:Connect(function()
local item = slotVal.Value
if equipped.Value ~= item then
remotes.ToInventory:FireServer(item)
end
end)
newSlot.Parent = hotbarGui
slotVal:GetPropertyChangedSignal("Value"):Connect(updateHotbar)
end
updateInventory(currentCategory)
inventory.ChildAdded:Connect(function() updateInventory(currentCategory) end)
inventory.ChildRemoved:Connect(function() updateInventory(currentCategory) end)
findSelectedSlot()
equipped:GetPropertyChangedSignal("Value"):Connect(findSelectedSlot)
uis.InputBegan:Connect(function(inp, p)
if p then return end
if table.find(keys, inp.KeyCode) then
local slotVal = hotbar:FindFirstChild(tostring(table.find(keys, inp.KeyCode)))
local item = slotVal.Value
remotes.Equip:FireServer(item)
end
end)
local function toggleInventoryVisibility()
local isVisible = not script.Parent.Background.Visible
for _, frame in pairs(inventoryCategories) do
frame.Visible = isVisible
end
script.Parent.Background.Visible = isVisible
script.Parent.SwordButton.Visible = isVisible
script.Parent.StaffButton.Visible = isVisible
script.Parent.BowButton.Visible = isVisible
script.Parent.ResourceButton.Visible = isVisible
end
uis.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then return end
if input.KeyCode == Enum.KeyCode.K then
toggleInventoryVisibility()
end
end)
openInvButton.MouseButton1Click:Connect(function()
toggleInventoryVisibility()
end)
-- Category buttons handling
local swordButton = script.Parent:WaitForChild("SwordButton")
local staffButton = script.Parent:WaitForChild("StaffButton")
local bowButton = script.Parent:WaitForChild("BowButton")
local resourceButton = script.Parent:WaitForChild("ResourceButton")
swordButton.MouseButton1Click:Connect(function()
currentCategory = "Swords"
updateInventory(currentCategory)
end)
staffButton.MouseButton1Click:Connect(function()
currentCategory = "Staffs"
updateInventory(currentCategory)
end)
bowButton.MouseButton1Click:Connect(function()
currentCategory = "Bows"
updateInventory(currentCategory)
end)
resourceButton.MouseButton1Click:Connect(function()
currentCategory = "Resources"
updateInventory(currentCategory)
end)