How would I make a delete train button?

My goal is to make a button that when you press it it will delete the entire train that your coupled to.

Also for protection you can only delete the whole train if you were the original spawner.
(To protect against people who can couple up to your train and delete it fast and easily)

But I am unsure how to even create this system.
I was thinking to do it through the couplers but im not sure how to do it.

  1. What I would say is firstly you would need to add some sort of vehicle spawn, so the user could spawn a train.
  2. However, in the train you could add a value that would update to the spawner’s name.
  3. You would also need to add a line in the spawn script that changes the value to the spawners name.
  4. You would then make a deleter button, and this script would first need to check the value, and see if it matches the spawner and the person trying to delete it.
  5. Lastly, if they match it would then go onto to deleting the model out the workspace.

(These are the steps I would use to approaching this but I recommend searching how to do script them if you need further help) :slightly_smiling_face:

oh I see
But how would I delete only the train and not uncoupled train cars

I’m not sure what you mean by “uncoupled train cars”

so the train on the left is uncoupled we do not it want deleted , its just train cars
but the train on the right is coupled because its got the locomotive in the consist

when we hit the delete train button the train on the right gets deleted but the train on the left doesn’t