Code issues - The inventory does not show the list

The inventory does not show the list when I take parts from the ground
I’m not sure what the problem is with the scripts or if something is missing but I would like to see the list of objects that I am adding to my inventory in the ‘UI’ that I indicate in the video on the left, when I press F in the object I want this object to be added to my inventory, could someone help me fix that problem please?

Project images:
image
image
image

Localscript → PickupManager

local UIS = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PickupItem = ReplicatedStorage:WaitForChild("PickupItem")
local pickupKey = "F"

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local PlayerGui = player:WaitForChild("PlayerGui")
local PickupInfoGui = PlayerGui:WaitForChild("PickupInfoGui")

UIS.InputChanged:Connect(function(input)
	if mouse.Target then
		if mouse.Target:FindFirstChild("Pickable") then
			local item = mouse.Target
			PickupInfoGui.Adornee = item
			PickupInfoGui.ObjectName.Text = item.name
			PickupInfoGui.Enabled = true
		else
			PickupInfoGui.Adornee = nil
			PickupInfoGui.Enabled = false
		end
	end
end)

UIS.InputEnded:Connect(function(input)
	if input.keyCode == Enum.KeyCode[pickupKey] then
		if mouse.Target then
			if mouse.Target:FindFirstChild("Pickable")then
				local item = mouse.Target
				if item then
					local distanceFromItem = player:DistanceFromCharacter(item.Position)

					if distanceFromItem < 30 then
						-- do stuff to pick up the item
						PickupItem:FireServer(item)
					end
				end
			end
		end
	end

end)

Localscript → InventoryHandler

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DropItem = ReplicatedStorage:WaitForChild("DropItem")

wait(3)

local player = game.Players.LocalPlayer
local Inventory = player.Inventory

local MainGui = script.Parent
local InventoryGui = MainGui.InventoryGui

for i, itemValue in pairs(Inventory:GetChildren())do
	itemValue.Changed:Connect(function()
		print("item value changed")
		local itemGui = InventoryGui.ItemList:FindFirstChild(itemValue.Name)
		
		if itemGui then
			itemGui.ItemQuantity.Text = itemValue.Value
			if itemValue.Value <= 0 then
				itemGui.Value = false
			else
				itemGui.Visible = true
			end
		end
	end)
end

Script → DataHandler

local ServerStorage = game:GetService("ServerStorage")
local InventoryTemplate = ServerStorage:WaitForChild("InventoryTemplate")

local function SetupInventory(player)
	local Inventory = player:WaitForChild("Inventory")
	local PlayerGui = player:WaitForChild("PlayerGui")
	local MainGui = PlayerGui:WaitForChild("MainGui")
	local InventoryGui = MainGui:WaitForChild("InventoryGui")
	
	for i, item in pairs  (Inventory:GetChildren()) do
		local itemGui = InventoryGui.Templates.Item:Clone()
		print(itemGui:GetFullName())
		itemGui.Name = item.Name
		itemGui.ItemName.Text = item.Name
		itemGui.ItemQuantity.Text = item.Value
		
		if item.Value > 0 then
			itemGui.Visible = true
			itemGui.Parent = InventoryGui.ItemList
		else
			itemGui.Visible = false
			itemGui.Parent = InventoryGui.ItemList
		end
	end
	
end

game.Players.PlayerAdded:Connect(function(player)
	
	local GameData = InventoryTemplate:Clone()
	GameData.Name = "Inventory"
	GameData.Parent = player
	
	
	SetupInventory(player)
end)

script → RemoteHandler

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local PickupItem = ReplicatedStorage:WaitForChild("PickupItem")

local pickupTweenInfo = TweenInfo.new(
	.3,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	0,
	false,
	0
)

local maxPickupDistance = 30

PickupItem.OnServerEvent:Connect (function(player, item)
	local char = player.Character
	local inventory = player.Inventory
	
	local itemValue = inventory:FindFirstChild(item.Name)
	
	if itemValue then
		itemValue.Value = itemValue.Value + 1
		
		local finishingLocation = char.HumanoidRootPart.CFrame
		item.CanCollide = false
		item.Anchored = true
		local tween = TweenService:Create(item, pickupTweenInfo, {Transparency = 1, Size = Vector3.new(0,0,0), CFrame = finishingLocation})
		tween:Play()
	end
end)
1 Like

Did you use this tutorial?

If so, the best thing you can do is simply re-watch it, double check your code, and try again

1 Like

Yes, I did it from that tutorial, I have checked it since the morning and I still cannot solve it. :frowning:

pd. I am using my custom inventory and that is why I ask for help, if someone could help me please I would appreciate it

In your error output, it says “Inventory is not a valid member of screengui”, meaning your gui is not found. Double check its name (no typos), how you define it in the script (make sure the name correlates). It says “not found” and “infinite wait on it”, so just double check the names and make sure there are no typos. Add

:WaitForChild()

to make sure it is available

Found your problem: your error is you didn’t define Background in your code.

PlayerGui.MainGui.Background.InventoryGui

when you did WaitForChild(“InventoryGui”) instead do

WaitForChild("Background").InventoryGui

That is your error. If you need me to explain further, I can

Wow, thank you very much! Do you think you can explain how to implement it, please :smiley:

local function SetupInventory(player)
	local Inventory = player:WaitForChild("Inventory")
	local PlayerGui = player:WaitForChild("PlayerGui")
	local MainGui = PlayerGui:WaitForChild("MainGui")
	local BackgroundGui = MainGui:WaitForChild("Background")
	local InventoryGui = BackgroundGui:WaitForChild("InventoryGui")

This will most likely fix the code since the one you were using wasn’t indexing the Background firstly, it was going from MainGui > InventoryGui rather than MainGui > Background > InventoryGui.

image

As you can see you gotta index background before hand.

local function SetupInventory(player)
	local Inventory = player:WaitForChild("Inventory")
	local PlayerGui = player:WaitForChild("PlayerGui")
	local MainGui = PlayerGui:WaitForChild("MainGui")
	local InventoryGui = MainGui:WaitForChild("InventoryGui")

unlike your one ^

lastly, what the person above was saying is

local MainGui = script.Parent
local Background = MainGui:WaitForChild("Background")
local InventoryGui = Background:WaitForChild("InventoryGui")

^ Make this edit to your inventory handler

Like this? or am i wrong? :scream: :scream:

local function SetupInventory(player)
	    local MainGui = script.Parent
        local Background = MainGui:WaitForChild("Background")
        local InventoryGui = Background:WaitForChild("InventoryGui")

LOL i’m a good friend of TheDevKing.

As you can see, in the first image it says:“InventoryGui is not a valid member of ScreenGui Players.MataisHeaders.PlayerGui.MainGui”

Try to fix this.

Edit:

That means you have to do:
PlayerGui.MainGui.Background.InventoryGui.

InventoryGui is not a child of the the ScreenGui, it’s a child of “Background”.

1 Like

Wow rlly?! lol xD
Something like this?

local ServerStorage = game:GetService("ServerStorage")
local InventoryTemplate = ServerStorage:WaitForChild("InventoryTemplate")

local function SetupInventory(player)
	local MainGui = script.Parent
	local Background = MainGui:WaitForChild("Background")
	local InventoryGui = Background:WaitForChild("InventoryGui")
	
	for i, item in pairs  (MainGui:GetChildren()) do
		local itemGui = InventoryGui.Templates.Item:Clone()
		print(itemGui:GetFullName())
		itemGui.Name = item.Name
		itemGui.ItemName.Text = item.Name
		itemGui.ItemQuantity.Text = item.Value
		
		if item.Value > 0 then
			itemGui.Visible = true
			itemGui.Parent = InventoryGui.ItemList
		else
			itemGui.Visible = false
			itemGui.Parent = InventoryGui.ItemList
		end
	end
	
end

game.Players.PlayerAdded:Connect(function(player)
	
	local GameData = InventoryTemplate:Clone()
	GameData.Name = "Inventory"
	GameData.Parent = player
	
	
	SetupInventory(player)
end)

I think so yeah. Did it work???

Got another error :frowning:

Change line 11 to:

local InventoryGui = MainGui.Background.InventoryGui

is it good?

image

Show the script in ServerScriptService

Remote Handler script:

   local ReplicatedStorage = game:GetService("ReplicatedStorage")
    local TweenService = game:GetService("TweenService")

    local PickupItem = ReplicatedStorage:WaitForChild("PickupItem")

    local pickupTweenInfo = TweenInfo.new(
    	.3,
    	Enum.EasingStyle.Linear,
    	Enum.EasingDirection.In,
    	0,
    	false,
    	0
    )

    local maxPickupDistance = 30

    PickupItem.OnServerEvent:Connect (function(player, item)
    	local char = player.Character
    	local inventory = player.Inventory
    	
    	local itemValue = inventory:FindFirstChild(item.Name)
    	
    	if itemValue then
    		itemValue.Value = itemValue.Value + 1
    		
    		local finishingLocation = char.HumanoidRootPart.CFrame
    		item.CanCollide = false
    		item.Anchored = true
    		local tween = TweenService:Create(item, pickupTweenInfo, {Transparency = 1, Size = Vector3.new(0,0,0), CFrame = finishingLocation})
    		tween:Play()
    	end
    end)

DataHandler script:

local ServerStorage = game:GetService("ServerStorage")
local InventoryTemplate = ServerStorage:WaitForChild("InventoryTemplate")

local function SetupInventory(player)
	local MainGui = script.Parent
	local Background = MainGui:WaitForChild("Background")
	local InventoryGui = Background:WaitForChild("InventoryGui")
	
	for i, item in pairs  (MainGui:GetChildren()) do
		local itemGui = InventoryGui.Templates.Item:Clone()
		print(itemGui:GetFullName())
		itemGui.Name = item.Name
		itemGui.ItemName.Text = item.Name
		itemGui.ItemQuantity.Text = item.Value
		
		if item.Value > 0 then
			itemGui.Visible = true
			itemGui.Parent = InventoryGui.ItemList
		else
			itemGui.Visible = false
			itemGui.Parent = InventoryGui.ItemList
		end
	end
	
end

game.Players.PlayerAdded:Connect(function(player)
	
	local GameData = InventoryTemplate:Clone()
	GameData.Name = "Inventory"
	GameData.Parent = player
	
	
	SetupInventory(player)
end)

why is ServerScriptService the MainGui???

Change

local MainGui = script.Parent

To

local MainGui = player.PlayerGui.MainGui

Becuz I did it following the tutorial :frowning:

image

I guess i can’t help you then. I know the guy who made this tutorial tho, i just can’t contact him rn.