Issue with adding to an inventory GUI

I want to create an inventory system for my mining game that adds ore names and the amount that the player has, and it gets stored in the GUI like how this screenshot is (not done with scripts, I just made this example by manually making it)
image

Whenever I mine a new ore it only shows the name of the first ore mined, and when it’s supposed to count up for one ore then it only counts up with the ‘new’ ores.

I’m getting it from a table and adding one to an index to find the new names from a table but it doesn’t work? I don’t know what’s going on anymore.

This is my code, I would appreciate it if anyone were to help.

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

local runService = game:GetService("RunService")

local Menu = script.Parent:WaitForChild("Frame")

local Inv = {}
local invCount = 0

runService.RenderStepped:Connect(function()
	if invCount == #player.Inventory:GetChildren() then return end
	
	invCount = #player.Inventory:GetChildren()
	
	for Index, Inst in ipairs(player.Inventory:GetChildren()) do
		if Inst:IsA("IntValue") then
			table.insert(Inv, Inst.Name)
		end
	end
	
	local invIndex = 0
	for Index, Inst in ipairs(Menu.ScrollingFrame:GetChildren()) do
		if Inst:IsA("TextButton") then
			invIndex += 1
			local thing = table.find(Inv, Inst.Name)
			if not thing then
				local newTB = Instance.new("TextButton", Menu.ScrollingFrame)
				newTB.BorderSizePixel = 0
				newTB.Size = UDim2.new(1, 0, 0.05, 0)
				newTB.Text = ""
				newTB.Name = Inv[invIndex]
				
				local newGrad = Instance.new("UIGradient", newTB)
				newGrad.Color = ColorSequence.new(Color3.new(1,1,1), Color3.new(0.435294, 0.435294, 0.435294))
				
				local oName = Instance.new("TextLabel", newTB)
				oName.Name = "oName"
				oName.BackgroundTransparency = 1
				oName.BorderSizePixel = 0
				oName.Position = UDim2.new(0.012, 0, 0, 0)
				oName.Size = UDim2.new(0.989, 0, 1, 0)
				oName.Font = Enum.Font.Roboto
				oName.Text = Inv[invIndex]
				oName.TextColor3 = Color3.new(1,1,1)
				oName.TextSize = 32
				oName.TextStrokeTransparency = 0
				oName.TextXAlignment = Enum.TextXAlignment.Left
				
				local oCount = Instance.new("TextButton", newTB)
				oCount.Name = "oCount"
				oCount.BackgroundTransparency = 1
				oCount.BorderSizePixel = 0
				oCount.Position = UDim2.new(-0.041, 0, 0, 0)
				oCount.Size = UDim2.new(0.989, 0, 1, 0)
				oCount.Font = Enum.Font.Roboto
				oCount.Text = 1
				oCount.TextColor3 = Color3.new(1,1,1)
				oCount.TextSize = 32
				oCount.TextStrokeTransparency = 0
				oCount.TextXAlignment = Enum.TextXAlignment.Right
			else
				Inst.oCount.Text = tostring(tonumber(Inst.oCount.Text) + 1)
			end
		end
	end
	
end)
1 Like

I fixed it by putting elements in this script into another one with the variables already existing within it

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.