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?
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)
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
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.
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")
local function SetupInventory(player)
local MainGui = script.Parent
local Background = MainGui:WaitForChild("Background")
local InventoryGui = Background:WaitForChild("InventoryGui")
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)
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)