Issue: I’ve scripted this code that you can see below for cloning a tool into the player’s backpack, although it doesn’t clone at all. Even when I printed the location of the cloned tool, it was in the players backpack, but there was nothing inside of there. I’m really confused and hope to find the issue here on the forum
local function copyItems(plr)
local playerItems = module.playerItems(plr)
for _,statvalue in pairs(playerItems) do
if(ssItems:FindFirstChild(statvalue) ~= nil) then
local foundItem = ssItems[statvalue]:Clone()
foundItem.Parent = plr.Backpack
print(foundItem.Parent.Parent.Parent)
else
warn("Didn't find", statvalue, "in the workspace")
end
end
end
Background info: the copyItems function is triggered when a player joins and on update.
game.Players.PlayerAdded:Connect(function(plr)
local Stats = plr:WaitForChild("Stats")
local Level = Stats:WaitForChild("Level")
local Items = Stats:WaitForChild("Items")
copyItems(plr)
Level:GetPropertyChangedSignal("Value"):Connect(function()
healthSetting(plr, Level)
print(module.maxExp(plr, Level))
end)
Items:GetPropertyChangedSignal("Value"):Connect(function()
copyItems(plr)
end)
-- local items = module.playerItems(plr)
-- module.addPlayerItem(plr, "5")
end)
playerItems is a table full of strings with ID’S of the player’s item’s ssItems is a folder with all the tools located in ServerStorage
can you post module.playerItems function? You called it in your copyItems function. And please don’t post screenshots of the code, it can be hard to read from a screenshot, and impossible for us to copy so we can reproduce your problem, instead directly paste the code into the body of your thread, in code block
Maybe you are not indexing the tables properly. When you run the code does it constantly end up printing “Didn’t find …”, from your copyItems function?
I’ve checked if it was the module.playerItems function’s fualt this was happening before, and it wasn’t but sure, here you have it!
function module.playerItems(player)
print("Start")
local Stats = player:WaitForChild("Stats")
local pID = Stats:WaitForChild("Items")
local playerItems = {}
local allItems = {
['1'] = "Beginner Sword",
['2'] = "Beginner Armor",
}
for a in pID.Value:gmatch("%w+") do
local item = allItems[a]
if(item) then
table.insert(playerItems, item)
else
warn("ID:", a, "was not found when searching", player.Name, "'s inventory")
end
end
print(table.concat(playerItems, " "))
return playerItems
end
You should try to use plr.CharacterAdded:wait() before you parent the item to the players backpack there is a bug that if the character is not loaded it will not put it correctly in the backpack from what I have ran into and tested in the past
I have also Isolated why this is happening. When the tool is added before the Character it is actually being added to the backpack but when the Character becomes part of the game it sets all parents of backpack items to nil