This is a server script and what i'm trying to accomplish is, once an npc has been killed it will drop a part. Once the part has been picked up it will give them an item, in this case a sword i'm not sure how to do it but this was my attempt. The sword just doesn't clone into the Backpack.
--//Services local serverStorage = game:GetService('ServerStorage') --//Variables local weapons = serverStorage:WaitForChild('Weapons') local myHum = script.Parent:WaitForChild('Humanoid') local myHead = script.Parent:WaitForChild('Head') --//Died myHum.Died:Connect(function() local dropChance = math.random(0,3) local itemChance = math.random(0,5) if dropChance == 3 or 2 or 1 then local p = Instance.new('Part') p.Anchored = true p.CanCollide = false p.Size = Vector3.new(3,3,3) p.Position = myHead.Position p.Parent = game.Workspace p.Touched:Connect(function(hit) if hit.Parent:FindFirstChild('Humanoid') and hit.Parent.Name ~= script.Parent.Name then local clone = weapons:WaitForChild('Sword'):Clone() clone.Parent = hit.Parent:FindFirstChild('Backpack') p:Destroy() end end) end end)
Backpack is a child of the player object. You were trying to find it under the player's character. You can get the player using GetPlayerFromCharacter:
p.Touched:Connect(function(hit) local parentModel = hit.Parent if parentModel then local player = game.Players:GetPlayerFromCharacter(parentModel) if player then local weapon = weapons:WaitForChild("Sword"):Clone() weapon.Parent = player.Backpack p:Destroy() end end end)