Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I make my inventory update all the time instead of only when I open it?

My inventory system only updates when i click to open the inventory gui. When i close the inventory gui it clears all the data until i open it again (which updates new or removed items).

I want it to be more real-time updating rather than only when i open and close the inventory. I've tried wrapping the whole thing in a while loop, but because of the button:clone() it causes the inventory to flicker every time it grabs the list.

Is there a way for me to arrange my code and to check for items being added/removed from the list while the inventory gui stays open?

if input.KeyCode == Enum.KeyCode.E then
	frame.Visible = not frame.Visible
	if frame.Visible then
		local inventory = 					game.ReplicatedStorage.RemoteFunctions.GetInventory:InvokeServer() -- get saved inventory
		for i=1, #inventory do  --loop entire inventory 
			local item = itemslist[tonumber(string.sub(inventory[i],1,3))] 
			local parentframe = frame["c"..item.class] -- item placed into correct class tab
			local n = #parentframe:GetChildren()
			local button = script.ImageButton:Clone()
			button.Image = item.image  
			button.Parent = parentframe
			button.code.Value = inventory[i] 
			button.slot.Value = i 
			local row = math.floor((n/6))
			local col = n-row*6
			button.Position = UDim2.new((0.15*col)+0.05,0,(0.02*row)+0.01,0)
			button.EquippedLabel.Position = UDim2.new(0.5,0,0.5,0)
			if string.sub(inventory[i],#inventory[i]) == "e" then
				button.EquippedLabel.Visible = true
			end
			button.Name = item.name
			local stats = item.stats
	else -- clear everything in gui on closing inventory gui
		for i=1,10 do
			local c = frame["c"..i]:GetChildren()
			for ii=1, #c do
				c[ii]:Destroy()
			end
		end
	end

1 comment

0

try adding a wait()

1 answer

Try making it update every time an item is added to or removed from the player's backpack. Here's an example:

local Player = game:GetService("Players").LocalPlayer
local Backpack = Player:WaitForChild("Backpack")

local function ItemAdded(Item)
	--Update Inventory
end

local function ItemRemoved(Item)
	--Update Inventory
end

Backpack.ChildAdded:Connect(ItemAdded)
Backpack.ChildRemoved:Connect(ItemRemoved)

1 comment

0

I'm not using the default backpack. My inventory is all kept in a table in the script.

This discussion is preserved as it was. New answers, comments, and votes are closed.