How can I make a road infinite?

I have finally finished the script (sorry for taking a while, I was taking a break). I will lead you through on how to set this up. Also you can change the length of the roads just make sure to change the new position vector.
image
Just make sure to make that number the same length in studs as your road.

local roadNumber = 1
local removedRoadNumber = -1

script.Parent.Touched:Connect(function(hit)
	print(hit.Name)
	if hit.Parent.Humanoid then
		roadNumber += 1
		removedRoadNumber += 1
		local newRoad = script.Parent.Parent:Clone()
		local oldRoad = game.Workspace[tostring(removedRoadNumber)]
		newRoad:SetPrimaryPartCFrame(CFrame.new(newRoad.PrimaryPart.Position + Vector3.new(55, 0, 0)))
		newRoad.Name = tostring(roadNumber)
		newRoad.Parent = game.Workspace
		oldRoad:Destroy()
		script:Destroy()
	end
end)

There’s the script and now here is how to set up the road parts.

image
In workspace there are models called 1 and 0, those are the roads (don’t worry about picnic table, that is something else)

I have only parts in the models but you can make it as intricate as you want. Don’t put any scripts in the road model “0”.
image
Just put the script under the part that the players will be walking on or the car that is touching.
Then finally you have to put them side to side like this:


And make sure that they are facing the right direction!

Hope this does it and tell me about your game when you are done :smiley:

I think you misunderstood me, the car isn’t moving. I just want the road to move to make it LOOK like the car is moving. Also, the car would be touching the road, not the player.

I can easily make it work if the car is touching it, but why do you want to make it look like it’s moving instead of it actually moving?

Because if the car goes too fast, players will fly off.

Is a player going to drive it because I might just be able to move it with a script.

No, player’s aren’t going to drive it.

Then how would the car go too fast to fling them off? And you said you wanted them to be on top of the car too?

They wouldn’t be sitting, but standing up. If the car were to go too fast, they would get flung off.

We can just weld them to the car?

You’re not helping me, you’re just asking questions. I asked for one simple thing.

Sorry I am just confused on what you want. I made an infinite road and you want them to stand on the car? I want to find solutions, I am sorry if I am asking to many questions. I just want to get it right.

The car is not moving, the players are on the car. The road is moving backwards to give it the illusion that the car is moving. I want the road to clone itself and delete the ones the car has already passed.

local TweenService = game:GetService("TweenService")

local road = script.Parent.Parent

local roadRoot = road.PrimaryPart

local moveInfo = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.In)

local moveTween = TweenService:Create(roadRoot, moveInfo, {CFrame = roadRoot.CFrame + Vector3.new(200, 0, 0)})

local function resetRoad()

moveTween:Play()

moveTween.Completed:Wait()

road:SetPrimaryPartCFrame(CFrame.new(roadRoot.Position - Vector3.new(200, 0, 0)))

end

while wait() do

resetRoad()

end

That is the script I came up with so that the car is not moving but the road is. I suggest making the road longer and add fog so that they can’t see it teleporting. Same thing as last time, you have to replace the Vector3 values with the length of your road.

Also I have a welding script so that you can attach any extra parts to the main road if you need that.

1 Like

I just recommend something easier, take a beam, make a road texture using paint or GIMP. Then apply that texture to the beam. Set its texture speed to 2 by typing it in. Then you have a moving road that doesn’t actually move, it will save lag.

2 Likes

How would you animate the texture? I actually want to know how to do this.

I think beam textures animate by themself

nothing to do with your discussion but actually I’m really struggling with a script that should make an entire model move infinitely in a certain direction and so … if you’re willing to help me with that, I will be really grateful to you (I mean…its kinda related to that message at least).

Thank you in advance

If you move an entire model too far from Position 0,0,0 then you start to get something called floating point error.
Since computers calculate values with a base 8 setup, trying to convert that to a base 10 number (decimals) results in very tiny decimal errors (like 0.0001 studs) but if you multiply that by something like 10000 studs from center you’d get a 1 stud difference in each Part’s Position. It wouldn’t be the same as the error in all the other Model’s Parts so all those Parts start to move around in relationship to each other.

Do you mean I have to make the model only one single part ?

If your player is going to be with the model it won’t work. Players are multiple Parts.
Also any movement of the model would be erratic since it’s Position would be jumping around.

1 Like