Creating Decoupling System For My Rockets

I have been trying to create a decoupling system for rockets where players can build their own rockets but idk how to make the decoupling work. Here’s what I mean. I want to make the stages of the rocket seperate from lowest to highest. If there are multiple decouplers they will decouple at the same time. Specifically that is the part I’m struggling with. Especially since I am extremely bad at tables. How do i do this. Need advice.

3 Likes

Time for some table manipulation!

It’s pretty simple to do this, all you need is a table to work with, and table.remove()
The best way to create a decoupling system will be to sort the table from first stage, to last stage, once you have a table of all your stages, you can set a variable of the stage activated. And then remove it from the table with table.remove(t, 1), and of course do your glorious decoupling!

Heres how it would look in practice:

-- your table wouldn't exactly look like this, i'd expect it to be filled with parts
local stages = {"firststage", "secondstage", "laststage"}

function decouple()
     local stage = stages[1] -- "firststage"
     table.remove(stages, 1)

     -- do something with the stage
     print(stage.." decoupled") -- "firststage decoupled"
end

decouple()

For further reference you should look at the documentation here

Eating food currently, created on the fly, code should work though

1 Like

Excellent this is what I need. But how do I get how many stages there are in a model.
Let’s just say that the stage name is “STAGE”
They have the same name but by sorting them by order. So the lowest Y position to the Highest Y.

1 Like