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)

1 comment
serverStorage should be game.ServerStorage also shouldnt hit.Parent.Name and script.Parent.Name have something between them?