I got this error on a script for an Inventory System. I Didn’t manage to fix it, if someone could help I’d really appreciate it
Here’s the script:
local player = game.Players.LocalPlayer
local character = player.Character
local items = {}
local buttons = {}
local equipbutton = script.Parent.Parent.EquipThing
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false) -- Makes the original backpack gui invisible
wait(.2)
function search(location)
for i,v in pairs(location:GetChildren()) do -- Find all item in a specific location
if v:isA("Tool") then -- If the item found is a "Tool"
table.insert(items,v) -- We're going to put all the tools found in a table.
end
end
end
function refresh()
for i,v in pairs(buttons) do -- Finds all items in the table
v:Destroy() -- Destroy 'em all
end
for i,v in pairs(items) do -- Finds all items in the table
local button = script.Sample:Clone() -- clones the sample button inside the localscript
local backpackframe = script.Parent:FindFirstChild(player.Backpack:FindFirstChild(v.Name).ItemType.Value.."BackpackFrame")
if backpackframe:FindFirstChild(v.Name) == nil then
button.Name = v.Name -- sets the cloned button's name to the name of the item
button.LayoutOrder = i
button.Parent = backpackframe -- Sets the parent of the cloned button to the handler
button.Image = v.TextureId -- Sets the image of the button to the texture id of the tool
button.ItemType.Value = player.Backpack:FindFirstChild(v.Name).ItemType.Value
table.insert(buttons,button) -- Inserts the button to our table "buttons"
button.MouseButton1Click:connect(function()
script.PopSound:Play()
if script.Selected.Value == nil or script.Selected.Value ~= v then -- Checks if the selected value is nothing or if the selected value is not the button
script.Parent.BackpackFrame.ItemName.Text = v.Name -- Sets the TextLabel's Text to the name of the tool/button
script.Parent.BackpackFrame.ItemRarity.Text = v.ToolTip -- Sets the item rarity written on the tooltip
script.Parent.BackpackFrame.ImageLabel.Image = v.TextureId -- Sets the image label's image to the texture id of the tool
script.Selected.Value = v
equipbutton.Image.Image = v.TextureId
equipbutton:TweenSize(UDim2.new(0.057, 0,0.122, 0), "Out", "Sine", .2)
equipbutton.Visible = true
if script.Selected.Value ~= script.Equipped.Value then --if the selected value is not the same as the equipped value then
script.Location.Value = v.Parent -- Sets the value of our location to the parent of the tool whether it is in the backpack or in the character
elseif script.Selected.Value == script.Equipped.Value then -- If the selected value is the same as the equipped value then...
script.Location.Value = v.Parent
end
end
if script.Parent.Parent:FindFirstChild(v.Name) then
script.Parent.Parent:FindFirstChild(v.Name):Remove()
end
end)
else
backpackframe:FindFirstChild(v.Name).Number.Value += 1
backpackframe:FindFirstChild(v.Name).Amount.Visible = true
backpackframe:FindFirstChild(v.Name).Amount.Text = 1+backpackframe:FindFirstChild(v.Name).Number.Value.."x"
end
button.MouseEnter:Connect(function()
local mouse = player:GetMouse()
local tooltipclone = script.TooltipSample:Clone()
tooltipclone.Name = v.Name
tooltipclone.Parent = script.Parent.Parent
tooltipclone.Namee.Text = v.Name
tooltipclone.Rarity.Text = v.ToolTip
tooltipclone.Position = UDim2.new(0,mouse.X,0,mouse.Y)
button.MouseLeave:Connect(function()
tooltipclone:Remove()
end)
end)
end
end
function backpackRefresh()
items = {}
search(character)
search(player.Backpack)
refresh()
end
backpackRefresh()
player.Backpack.ChildAdded:connect(backpackRefresh)
player.Backpack.ChildRemoved:connect(backpackRefresh)
character.ChildAdded:connect(backpackRefresh)
character.ChildRemoved:connect(backpackRefresh)
