Hi, I have a script that will distribute parts over my map but after they have spawned in and dropped to the ground they will just be removed. I can't figure out why this is happening.
This is the script that clones the part and drops the cloned parts across the map:
for original = 1, 75 do local pos1 = math.random(-1024, 1024) local pos2 = math.random(-1024, 1024) local original = game.Workspace.Health local copies = original:Clone() copies.Parent = original.Parent copies.Position = Vector3.new(pos1, 50, pos2) copies.Anchored = false end
Any and all help will be appreciated!
That is because Anchored is set to false. Please re-enable it and let me know how it goes.
You are using variable original
both as a indices and health item reference. You should never use variables with the same name, as it may cause some really weird bugs. Please change your code like this:
local original = game.Workspace.Health -- that line can be outside loop for i = 1, 75 do local pos1 = math.random(-1024, 1024) local pos2 = math.random(-1024, 1024) local copies = original:Clone() copies.Parent = original.Parent copies.Position = Vector3.new(pos1, 50, pos2) copies.Anchored = false end
As SmartNode mentioned, if your health item is non collidable, it will fall through and get destroyed by engine. Make sure CanCollide is set to true for your items.