Hello, I have made an inventory system which functions but its horrible.
Image: Click me to see
Note: This is one of the problems it has, there are more glitch’s.
Here is the script that handles the GUI, If you want the server script please DM me on discord
Nv#5064
local updateInv = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("UpdateInventory")
local UIS = game:GetService("UserInputService")
local equipRemote = game:GetService("ReplicatedStorage").Remotes.EquipItem
local unequipRemote = game:GetService("ReplicatedStorage").Remotes.UnequipItem
local invButtons = script.Parent.Parent.Frame.Inventory.Frame.ScrollingFrame
local equippedButtons = script.Parent.Parent.Frame.Equipped.Frame.ScrollingFrame
local equipHitbox = script.Parent.Parent.Frame.Equipped
local invHitbox = script.Parent.Parent.Frame.Inventory
local infoFrame = script.Parent.Parent.Frame.Information
local dropArea = script.Parent.Parent.Frame.DropArea
local dropRemote = game:GetService("ReplicatedStorage").Remotes.DropItem
local enabled = script.Parent.enabled
local inEquip = false
local inInv = false
local inDrop = false
function updateInventory(inventory)
print('Updating inventory..')
for i,v in pairs(script.Parent.Parent.Frame.Equipped.Frame.ScrollingFrame:GetChildren()) do
if v:IsA("TextButton") then
v:Destroy()
end
end
for i,v in pairs(script.Parent.Parent:GetChildren()) do
if v:IsA("TextButton") then
v:Destroy()
end
end
for i,v in pairs(script.Parent.Parent.Frame.Inventory.Frame.ScrollingFrame:GetChildren()) do
if v:IsA("TextButton") then
v:Destroy()
end
end
for i,v in pairs(inventory.Items) do
local button = Instance.new("TextButton")
local itemType = Instance.new("StringValue", button)
itemType.Name = "Type"
itemType.Value = v.Type
local desc = Instance.new("StringValue", button)
desc.Name = "Description"
desc.Value = v.Description
local name2 = Instance.new("StringValue", button)
name2.Name = "ServerName"
name2.Value = i
local name = Instance.new("StringValue", button)
name.Name = "DisplayName"
name.Value = v.Name
local amount = Instance.new("IntValue", button)
amount.Name = "Amount"
amount.Value = v.Amount
--// Creating The TextButton for the Inventory
button.Size = UDim2.new(0,250,0,30)
button.BackgroundColor3 = Color3.fromRGB(140,120,100)
button.TextColor3 = Color3.new(222,255,255)
button.BackgroundTransparency = 0
button.Text = (name.Value .. " " .. amount.Value)
button.Parent = invButtons
end
for i,v in pairs(inventory.Equipped) do
local button = Instance.new("TextButton")
local desc = Instance.new("StringValue", button)
desc.Name = "Description"
desc.Value = v.Description
local name2 = Instance.new("StringValue", button)
name2.Name = "ServerName"
name2.Value = i
local name = Instance.new("StringValue", button)
name.Name = "DisplayName"
name.Value = v.Name
local amount = Instance.new("IntValue", button)
amount.Name = "Amount"
amount.Value = v.Amount
--//Creating The TextButton for the equipped items
button.Size = UDim2.new(0,250,0,30)
button.BackgroundColor3 = Color3.fromRGB(140,120,100)
button.TextColor3 = Color3.new(222,255,255)
button.BackgroundTransparency = 0
button.Text = (name.Value .. " " .. amount.Value)
button.Parent = equippedButtons
end
print("Updated inventory.")
updateListeners()
end
function setTargetDrop()
inDrop = true
end
function unsetTargetDrop()
inDrop = false
end
function setTargetEquip()
inEquip = true
end
function unsetTargetEquip()
inEquip = false
end
function setTargetInv()
inInv = true
end
function unsetTargetInv()
inInv = false
end
function updateListeners()
for i,v in pairs(script.Parent.Parent.Frame.Inventory.Frame.ScrollingFrame:GetChildren()) do
if v:IsA("TextButton") then
v.MouseButton1Down:Connect(function()
dropArea.Visible = true
infoFrame.Info.TextLabel.Text = v.Description.Value
infoFrame.DisplayName.TextLabel.Text = v.DisplayName.Value
local origParent = v.Parent
v.Parent = script.Parent.Parent
repeat
v.Position = UDim2.new(0,mouse.X,0,mouse.Y)
wait()
until UIS:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) == false
if inEquip == true then
local result = equipRemote:InvokeServer(v.ServerName.Value)
if result ~= false then
v:Destroy()
else
print("NotEquippable")
v.Parent = origParent
end
else
if inDrop == true then
if v.Parent == nil then return end
local result = dropRemote:InvokeServer(v.ServerName.Value)
if result ~= false then
v:Destroy()
dropArea.Visible = false
return
end
if v then
v.Parent = origParent
end
end
if v.Parent ~= nil then
v.Parent = origParent
end
end
dropArea.Visible = false
end)
end
end
for i,v in pairs(script.Parent.Parent.Frame.Equipped.Frame.ScrollingFrame:GetChildren()) do
if v:IsA("TextButton") then
v.MouseButton1Down:Connect(function()
infoFrame.Info.TextLabel.Text = v.Description.Value
infoFrame.DisplayName.TextLabel.Text = v.DisplayName.Value
local origParent = v.Parent
v.Parent = script.Parent.Parent
repeat
v.Position = UDim2.new(0,mouse.X,0,mouse.Y)
wait()
until UIS:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) == false
if inInv == true then
if v.Parent == nil then return end
local result = unequipRemote:InvokeServer(v.ServerName.Value)
if result ~= false then
v:Destroy()
end
end
if v.Parent ~= nil then
v.Parent = origParent
end
end)
end
end
end
dropArea.MouseEnter:Connect(setTargetDrop)
dropArea.MouseLeave:Connect(unsetTargetDrop)
equipHitbox.MouseEnter:Connect(setTargetEquip)
equipHitbox.MouseLeave:Connect(unsetTargetEquip)
invHitbox.MouseEnter:Connect(setTargetInv)
invHitbox.MouseLeave:Connect(unsetTargetInv)
updateInv.OnClientEvent:Connect(updateInventory)