Hi guys ive been working on a script inside of a NPC, his main purpose is to spawn a part in a folder using :Clone() and MoveTo. I have a folder inside ReplicatedStorage in which the item is in but they are more than 1 item so i made a random item picker. unfortunately, for a reason that i does not know, it does not work at all and shows nothing in the output. Am i missing something ?
Here's the code:
local humanoid = script.Parent.Humanoid local alive = true local health = humanoid.Health local dead = health >0 local Object = game.ReplicatedStorage.Item local die = false function pick(part) local children=Object:GetChildren() local chosen=children[math.random(1,#children)] local position = script.Parent.HumanoidRootPart.Position local itemspawn = chosen:Clone() itemspawn.Parent = game.Workspace itemspawn:MoveTo(position) if dead then alive = false end wait(.5) pick(Object) return chosen end