Hi everyone I’m currently working on an Inventory System and rn I have a Clone function that duplicates my Tools when I die, in the Inventory.Now 2 days ago I deleted the :Clone() function and the Problem has been solved but now I tested it again and it gave me this error:ItemButton is not a valid member of Frame “Players.Nemmo1232.PlayerGui.InventoryGui.InventoryFrame.ItemsFrame”. This is the LocalScript:
local InventoryEvent = game.ReplicatedStorage.Remotes.InventoryEvent
local itemFrame = script.Parent:FindFirstChild("ItemsFrame")
InventoryEvent.OnClientEvent:Connect(function(ItemName, Value)
if Value == true then
local ItemButton = script.Parent.ItemsFrame.ItemButton:Clone()
ItemButton.Visible = true
ItemButton.Name = ItemName
ItemButton.Text = ItemName
ItemButton.Parent = itemFrame
local equipButton = script.Parent.EquipFrame["EquipButton"]
ItemButton.MouseButton1Click:Connect(function()
script.Parent.EquipFrame.Title.Text = ItemName
script.Parent.EquipFrame.Title.Visible = true
equipButton.Visible = true
end)
end
end)
I think the problem is that you do script.Parent Instead of using the actual playerGui. starter GUI is just meant for storing the GUI, and basically giving it to all of the players. try doing this:
local GUI = game.Players.LocalPlayer.PlayerGui.ScreenGUI --whatever your screenGUI is named.
local InventoryEvent = game.ReplicatedStorage.Remotes.InventoryEvent
local itemFrame = script.Parent:FindFirstChild("ItemsFrame")
InventoryEvent.OnClientEvent:Connect(function(ItemName, Value)
if Value == true then
local ItemButton = GUI.ItemsFrame.ItemButton:Clone()
ItemButton.Visible = true
ItemButton.Name = ItemName
ItemButton.Text = ItemName
ItemButton.Parent = itemFrame
local equipButton = GUI.EquipFrame["EquipButton"]
ItemButton.MouseButton1Click:Connect(function()
GUI.EquipFrame.Title.Text = ItemName
GUI.EquipFrame.Title.Visible = true
equipButton.Visible = true
end)
end
end)
well it does the same I think Ik why.I didn’t show the script that is connected with and don’T I have to delete the clone function?
local inventoryEvent = game.ReplicatedStorage.Remotes.InventoryEvent
game.Players.PlayerAdded:Connect(function(player)
local inventory = player:WaitForChild("Inventory")
local inventoryFrame = player.PlayerGui:WaitForChild("InventoryGui").InventoryFrame.ItemsFrame:GetChildren()
inventory.ChildAdded:Connect(function(Item)
inventoryEvent:FireClient(player, Item.Name, true)
end)
end)
inventoryEvent.OnServerEvent:Connect(function(player, ItemName, Value, button)
if Value == false then
local SelectedItem = player.Inventory:FindFirstChild(ItemName)
local backpack = player.Backpack:GetChildren()
local stuff = player.Character:GetChildren()
if #backpack == 0 and not player.Character:FindFirstChildWhichIsA("Tool") then
button.Text = "Unequip"
button.BackgroundColor3 = Color3.new(255,0,0)
SelectedItem:Clone().Parent = player.Backpack
else
for i,v in ipairs(backpack) do
button.Text = "Equip"
button.BackgroundColor3 = Color3.new(0,255,0)
v:Destroy()
end
for i, v in ipairs(stuff) do
if v:IsA("Tool") then
button.Text = "Equip"
button.BackgroundColor3 = Color3.new(0,255,0)
v:Destroy()
end
end
end
end
end)
I just want to delete the Clone function or like stop it from Cloning somehow I remember I had a similar issue once and I think it was in the Script I pasted u
Is there a way I can fix this somehow?like delete the Clone and Children function.And I have a question does the Clone function in this part:if #backpack == 0 and not player.Character:FindFirstChildWhichIsA(“Tool”) then
button.Text = “Unequip”
button.BackgroundColor3 = Color3.new(255,0,0)
SelectedItem:Clone().Parent = player.Backpack have nothing to do with the Clone issue?
The ItemButton is not a valid member of the Frame named ItemsFrame. This error is occurring in the LocalScript.
The items are being duplicated when the player respawns, as the inventoryEvent is being fired for each child of the InventoryGui on the player’s respawn.
The Clone() function is causing duplication of the tools when the player dies.
local InventoryEvent = game.ReplicatedStorage.Remotes.InventoryEvent
local itemFrame = script.Parent:FindFirstChild("ItemsFrame")
-- Ensure itemFrame is valid
if not itemFrame then
warn("ItemsFrame not found")
return
end
-- Clear the inventory when the player respawns
local function clearInventory()
for _, child in pairs(itemFrame:GetChildren()) do
if child:IsA("GuiButton") then
child:Destroy()
end
end
end
-- Connect to the player's respawn event
game.Players.LocalPlayer.CharacterAdded:Connect(function()
clearInventory()
end)
InventoryEvent.OnClientEvent:Connect(function(ItemName, Value)
if Value == true and itemFrame:FindFirstChild("ItemButton") then
local ItemButtonTemplate = itemFrame.ItemButton
local ItemButton = ItemButtonTemplate:Clone()
ItemButton.Visible = true
ItemButton.Name = ItemName
ItemButton.Text = ItemName
ItemButton.Parent = itemFrame
local equipButton = script.Parent.EquipFrame:FindFirstChild("EquipButton")
if equipButton then
ItemButton.MouseButton1Click:Connect(function()
script.Parent.EquipFrame.Title.Text = ItemName
script.Parent.EquipFrame.Title.Visible = true
equipButton.Visible = true
end)
else
warn("EquipButton not found in EquipFrame")
end
elseif not itemFrame:FindFirstChild("ItemButton") then
warn("ItemButton template not found in ItemsFrame")
end
end)
definitely try what the guy above said. also, I noticed that when you equip a tool, it leaves your backpack, and goes to the character, then when you unequip it, it goes back to the backpack, so that might be another issue you should look out for.
I would also suggest you Index the ItemButton at the very top since you are creating a new clone every time the Event is called anyway.
local InventoryEvent = game.ReplicatedStorage.Remotes.InventoryEvent
local itemFrame = script.Parent:WaitForChild("ItemsFrame")
local ItemButton = itemFrame:WaitForChild("ItemButton")
thank y’all 2 for the response but when I die the Inventory gets cleared fully like all tools in there disappear although I want the Tool that gets duplicated when I die to disappear sry for being annyoing
Dude wth I promise this is the last thing ima ask y’all then ima try figure it out by myself but now it gave me an error which says: ServerScriptService.InventoryScript:25: attempt to index nil with ‘Clone’.This is the Script:
local inventoryEvent = game.ReplicatedStorage.Remotes.InventoryEvent
game.Players.PlayerAdded:Connect(function(player)
local inventory = player:WaitForChild("Inventory")
local inventoryFrame = player.PlayerGui:WaitForChild("InventoryGui").InventoryFrame.ItemsFrame:GetChildren()
inventory.ChildAdded:Connect(function(Item)
inventoryEvent:FireClient(player, Item.Name, true)
end)
end)
inventoryEvent.OnServerEvent:Connect(function(player, ItemName, Value, button)
if Value == false then
local SelectedItem = player.Inventory:FindFirstChild(ItemName)
local backpack = player.Backpack:GetChildren()
local stuff = player.Character:GetChildren()
if #backpack == 0 and not player.Character:FindFirstChildWhichIsA("Tool") then
button.Text = "Unequip"
button.BackgroundColor3 = Color3.new(255,0,0)
SelectedItem:Clone().Parent = player.Backpack
else
for i,v in ipairs(backpack) do
button.Text = "Equip"
button.BackgroundColor3 = Color3.new(0,255,0)
v:Destroy()
end
for i, v in ipairs(stuff) do
if v:IsA("Tool") then
button.Text = "Equip"
button.BackgroundColor3 = Color3.new(0,255,0)
v:Destroy()
end
end
end
end
end)