Hello,

Below is my custom inventory script. The script is suppose to save items inside the inventory, but sometimes it randomly empties the items from the backpack. I'm not sure whats causing the random emptying. There is no output errors that I see, does anyone see an error or way to fix this? Thanks.


local player = game.Players.LocalPlayer

local StarterGui = game:GetService('StarterGui')
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

local Enabled = false

player.CharacterAdded:wait() 
function UpdateInventory()
	if Enabled == false then
		Enabled = true
		script.Parent.Frame.Visible = true
		script.Parent.Frame.CanvasSize = UDim2.new(0,0,0,20*#player.Backpack:children())
		script.Parent.Frame:ClearAllChildren()
		for i,v in pairs(player.Backpack:GetChildren()) do
			local Obj1 = Instance.new('TextButton',script.Parent.Frame)
			Obj1.Size = UDim2.new(1,-12,0,20)
			Obj1.Position = UDim2.new(0,0,0,20*i-20)
			Obj1.BackgroundTransparency = 1
			Obj1.FontSize = 'Size24'
			Obj1.Text = v.Name
			Obj1.Font = 'SourceSansBold'
			Obj1.TextColor3 = Color3.new(255,255,255)
			Obj1.TextXAlignment = 'Left'
			Obj1.MouseButton1Down:connect(function()
				player.Character.Humanoid:UnequipTools()
				player.Character.Humanoid:EquipTool(v)
			end)
		end
	else
		Enabled = false
		script.Parent.Frame.Visible = false
	end
end

script.Parent.InvenButton.MouseButton1Down:connect(function()
	UpdateInventory()
end)

-- BELOW

script.Parent.ImageButton.MouseButton1Down:connect(function()
	UpdateInventory()
end)

-- ABOVE

player.Backpack.Changed:connect(function()
	if Enabled == false then Enabled = true UpdateInventory() end
	if Enabled == true then Enabled = false UpdateInventory() end
end)


2 comments

0

Reposting is not allowed. Please narrow down your problem to no more than 15-20 lines, and include a detailed explaination of what is supposed to happen and what is actually happening. If no one is replying, you are probably making it difficult for us to help.

0

Hello, thanks for the response. If no one responds to the previous request, and I still need assistance as the problem has not been solved, what is the proper protocol? I've edited my message to make it briefer.