Why is it making so many clones despite my filter, and how can i stop it?

So, i’ve been really trying to make a scrolling street script, but i’ve ran into a total road block that not only slows the game’s FPS by a large amount, but does it so many times the road scrolling gets completely ran over by the fact the road itself is moving so fast, so i need help to try and get this to work…

what i want to acheive is a road scrolling effect like that you see in bus simulator, how the road continously goes backwards.

local Number = 1
local PastNumber = 0
local PastPastNumber = -1
local Template = game.Workspace.StreetTemplate1

while Number < 3000 do
	wait(1)
	for i,v in pairs(game.Workspace.StreetTemplate1:GetChildren()) do
		wait()
		if v.Name == "New"..(PastNumber) or "Curb" or "Grass" or "Median" or "Sidewalk" or "Street" or "Street Edge" and not "New"..(PastPastNumber) then
			local new = v:Clone()
			new.Parent = Template
			new.Name = "New"..(Number)
			new.Position = v.Position - Vector3.new(67.203,0,0)
		else
			
			return
				
				
		end
	end
	PastPastNumber = PastPastNumber + 1
	PastNumber = PastNumber + 1
	Number = Number + 1
end

note that i created the road moving in another script, and it is not causing any errors
thanks for reading and,
please help!

This might have to do something with that. Basically, what we are doing here is:
If the name of v is “New”…(PastNumber) OR the string “Curb” exists OR the string “Grass” exists… clone v
I’m pretty sure this isn’t what you want, so this line should be:

if v.Name == "New"..(PastNumber) or v.Name = "Curb" or v.Name = "Grass" -- you get the idea

Sidenote, but using CollectionService would probably be way cleaner.

2 Likes

CollectionService? never heard of that…

your script Clone the parts in game.Workspace.StreetTemplate1 3000 times idont get what do you want the script do

CollectionService | Roblox Creator Documentation Basically, you can tag all the stuff you want to clone.