I want to make a script that make an object yo spawn randomly on an área. I did the random spawn script, and It works, but I have problems with the despawn script. I made it by writting
game.Workspace:FindFirstChild:("clonedpart"):Destroy(), and it works, but it only deletes/despawns one of the objects, and after that it stops. Any idea?
2 Likes
So i am a very new scripter so if i am wrong please feel free to correct me but couldn’t you use a ‘For Loop’ to list all of the parts with that name and destroy them all?
for instance
For i, object in pairs(game.Workspace:GetChildren(“clonepart”)) do
object:Destroy()
end
the reason of using the for loop would be to grab multiple objects not just one with your current script only grabbing the first child.
1 Like
This should work:
for _, v in pairs(game.Workspace:GetChildren()) do
if v.Name == “clonedpart” then
v:Destroy()
end
end
2 Likes