How do I generate my road infinitely?

Heyy guys
I need to make it so that a road gets generated infintely, and if the player goes out of one block it despawns to prevent lag. I tried this post too [SOLVED] Help on infinite road
but i cant understand how it works and how i can put it in my road.
Thanks for help.

2 Likes

You dont need to make new road parts/models actually, i suggest you the positioning.
like if your road is 50 studs long, road.position = road.position + vector3.new(50,0,0),
so it looks like generating and takes less performance about lag with that, you can use ontouched function about the road gets lost. Just 3 parts of road could be enough for that idea.

3 Likes

I tried to do that. Heres my srvr script under the collision part.

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local clone = game.ServerStorage.Road:Clone()
		clone.Parent = workspace
		clone:PivotTo(clone.Road.Position.X + 60, clone.Road.Position.Y, clone.Road.Position.Z)
	end
end)

but it doesnt work :confused: no errors. What could be wrong?
Edit: o wait i got what u want to say, but it didnt work. its the same script above:

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		script.Parent.Parent:PivotTo(script.Parent.Parent.Road.Position.X + 60, script.Parent.Parent.Road.Position.Y, script.Parent.Parent.Road.Position.Z)
	end
end)

I got it working thanks for helping me. Have a nice day!

1 Like

np, i was going to send you a working script if you wasnt said that :smiley:

1 Like

One question, my game is a bit high speed based, and some times the touched doesnt fire. how can i fix that?

1 Like

hmm good question, maybe make roads longer? because this time i dont think there is much than a ontouched function…

My bad damn. I was moving the road but not the collision part itself. Sorry to blame the roblox touched event for that it works nice. My fault lol, moved the collision part also and it works flawlessly.

Welp thats good to hear, good works on your game!

1 Like