Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Parts disappearing after being cloned?

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!

1 comment

0

I found out that it was actually a script inside the parts that was causing them to be deleted, but all of the answers on this were also very helpful, thank you!

2 answers

✓ Accepted answer

That is because Anchored is set to false. Please re-enable it and let me know how it goes.

4 comments

0

Seems to be working now, thank you. Do you know if there's any way I could have them not be anchored that wont break them?

0

If only the cloned ones are breaking, just stop setting the anchored property completely. When you :Clone() an object you copy the name and properties altogether so it should not break as long as the original doesn’t break.

0

I see, thanks again!

0

No problem, happy to help!

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.