I want to create a game where players are on a train that is seemingly moving infinitely, but the roads are actually moving backwards to create the effect of an infinitely moving train. What I am trying to accomplish is much like the Infinite Road trip game (An Infinite Road Trip - Roblox)
I created a base(?) like model that does create parts infinitely and when a player goes to a point it adds on another, but I want to tweak some of that.
The code I made is dependent on the player walking themselves over to said point to create more, but I want to make it to where if that end point touches a part of the train or a part (like the front), it creates more road pieces. And for the train to get to that point, I need the road pieces to be moving backwards constantly (I cant have the train move because I want players to be able to walk on top of the train and move around it.
I also want unneeded rooms to delete themselves once it gets past a certain point, so that the game does not lag.
I followed a tutorial video to create my code, which I’ll link here to give you guys an idea of what my code looks like (I followed it to a T) I will also send a copy of the game so you guys can go into studio and look at the code (if you want)
Video Link: https://www.youtube.com/watch?v=s2XUzTyCdK4&ab_channel=ByteBlox
Game link: Infinite Rooms - Roblox
I’m not very familiar with tweening and making moving parts, so I would appreciate the help
I’m not entirely sure what you’re trying to achieve, but from how I understand it you simply want a train with moving surroundings.
You can just create a loop for that which always generates new tracks and tweens and after some time they get automatically destroyed.
That way it won’t affect your games memory a lot and it will look like the train is moving on infinite tracks.
Since you said your not very familiar with tweening here’s how I did it:
For this I’m using a model “Train” with a basic spawnlocation inside as my train
The tracks is basically a model with 2 differently colored parts, this is to show I’m actually working with models, because tweening works a little different for models and parts.
I made a folder “Tracks” in workspace that all tracks will be generated into. I also had a “Train” model in the workspace.
Then create a script with this code in serverscriptservice:
local track = script.Track
local trackFolder = workspace.Tracks
local train = workspace.Train
local ts = game:GetService("TweenService")
while wait(.7) do
local c = track:Clone()
c.Parent = trackFolder
c.PrimaryPart.CFrame = train.PrimaryPart.CFrame + Vector3.new(0, 0, 250)
ts:Create(c.PrimaryPart, TweenInfo.new(4, Enum.EasingStyle.Linear), {CFrame = c.PrimaryPart.CFrame - Vector3.new(0,0,500)}):Play()
c.destroyingScript.Enabled = true
end
Inside the script, put a “Tracks” model, make sure it’s welded correctly and all parts but the primarypart are unanchored.
Inside the “Tracks” model I made a simple script called “destroyingScript”. Make sure this script is disabled and the main script is enabled.
Destroying script:
wait(4)
script.Parent:Destroy()
Also make sure the train model also has a primarypart since we’re gonna be using that to define the track position.
Depending on your model sizes you’re gonna have to twist the values around, for example the time for the loop, the tween goal and the tween time. My tracks were 200 studs long for this test.
I also attached a screenshot of the explorer. If you need any more help feel free to reply to this.
Make sure you follow my tutorial carefully. The explorer should look about the same. For this you probably just didn’t set the PrimaryPart correctly. Go to the “Track” model’s properties and set the PrimaryPart to any part of the model that is welded with all the other model’s parts.
@infinityTNT Please let me know if it worked, if not I can provide further assistance.
If it worked please mark the post as solution for other users on the devforum