Spawning objects after another is collected

Basically what I want to do is, when players spawn in the map a few seconds later parts began to spawn, for right now 1 is fine. So the part spawns and it reveals the location to the players (like an adornee or surface gui), so what I want is when the part spawns a player can pick it up (I already have the script for collection) and when they do another part spawns a few seconds later, in a different section or area. Basically I want the part only to appear/spawn when the other is collected. Sort of like a race to grab it before another player does.

I found a way to do it with boolvalues but its really ineffective and I don’t want to have like 100 parts waiting for its turn to spawn.

In my opinion, the easiest (and least resource-consuming) option would just be to change the part’s Position once a player collects it. Whether that collection happens with an onTouch event or whatever else you may be using. That’s assuming all the parts look the same. But even if they didn’t you could just change its appearance once you’ve moved it to the new position.

1 Like

If you really need the parts to be separate instances you could just clone the part and set it to the new position. Something like:

local newPart = part:Clone()
newPart.Position = Vector3,new(0, 0, 0) -- Wherever the new position is
newPart.Parent = Workspace

part:Destroy()

This should be inside your collection function or script, probably at the end.

Make a module script for your drop logic.

-- droplogic
function module.myDropLogic()
local Part = .....

return Part
end

return module

Then, in a script,


local module = require(modulescript)
local currentDrop = x

function pickupItem()
 -- Connect this to whatever pick up logic you have.

local newDrop = module.myDropLogic()

end

currentDrop.Touched:connect(pickupItem)

This will drop a new part after the old one has been picked up.

Pretty simple you can make a bool value inside every tool so when the tool is picked up the value becomes true and it disappears then the next tool spawns

Yeah I did it that way and its too messy, the thing is I need more than a couple parts and doing it that way is really ineffective and sloppy. Its why I asked if there was another way.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.