How can I make a infinite train track using scripts?

This is my first post so remind me if im doing something wrong.
You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I’d like to make a train track that spawns in new tracks as you go through the track. (Basically infinite)
  2. What is the issue? Include screenshots / videos if possible!
    No issue except for the fact that I cant find any tutorials on the internet (Big surprise)
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried cloning the track then putting it in front of the track that the train is currently on, but it didn’t work.
1 Like

just take a new track from replicated storage and make it appear Infront of the train/player every time their humanoid is not touching the previous.

and don’t forget to make it destroy the previous track if you want less lag at the end of the day.

this is from my basic understanding after watching way to many Alvin Blox videos for many many years haha.

1 Like

Thanks. I’ll try you’re solution when I get the chance.

This is actually a pretty difficult coding challenge.

Does your track really need to be infinite? If not you will go through a lot of hassle by trying to implement a feature you didn’t really need.

Anyway if you decide to make it truly infinite, here’s how I would do it: have an infinite loop that periodically checks the player’s position. If their position has changed enough, then Spawn in extra tracks in the direction of their movement.
Make sure to despawn tracks in the opposite direction for performance reasons.

It might be worth it to look at examples of ‘infinite tile generation’.

1 Like