The script isn't adding the items to the inventory as asked and there's no output errors!
There's probably something way wrong with this script but here it is!
--//ITS A LOCAL SCRIPT\--
local player = game.Players.LocalPlayer local template = script.Parent.Parent.Template wait(player.CharacterAdded) function addItems() local invItems = player.Inventory:GetChildren() if invItems == "TestItem" then local clonedTemp = template:Clone() clonedTemp.Parent = script.Parent clonedTemp.InfoValues.Gives.Value = 1 clonedTemp.InfoValues.Name.Value = "TestItem" clonedTemp.Visible = true end end addItems()
Despite incapaxx's comment (I literally have no idea what he's talking about; he's probably high again), :GetChildren()
returns a table. This means that invItems
will never be equal to TestItem
. If you printed it, you'd get a TableId outputted. I'm assuming Inventory
is a folder or any data container that you've created, and you want to scan inside it for the so called TestItem
. To accomplish this, you'll have to loop through the table returned by :GetChildren()
, i.e. invItems
.
local player = game.Players.LocalPlayer local template = script.Parent.Parent.Template wait(player.CharacterAdded) function addItems() local invItems = player.Inventory:GetChildren() for _,v in pairs(invItems) do if v.Name == "TestItem" then local clonedTemp = template:Clone() clonedTemp.Parent = script.Parent clonedTemp.InfoValues.Gives.Value = 1 clonedTemp.InfoValues.Name.Value = "TestItem" clonedTemp.Visible = true end end end addItems()
Miniller did actually have the right idea. He simply didn't elaborate on it enough.
Problem 01:Line 08 is not working, because player.Inventory:GetChildren() returns a table. Problem 02:It's Backpack, not Inventory, Problem 03: I don't think wait(player.CharacterAdded) is working, because there you need to write a number... For that, you need to add an event like this:
player.CharacterAdded:Connect(function() --put all your code (except the line01) there! end)
For the other problems I said, the backpack and the table thing, use
for i = 1, #player.Backpack:GetChildren() do print(player.Backpack:GetChildren()[i]) end --This code will print all tools in backpack.
instead of what you used. Also, where is this script at? I need to know that! Tell me where is the script, and I can help you to re-script that.