How do I optimise this car loop?

Code below, currently it seems very glitchy and unoptimised, anyone got ideas to make it better?

The script is for a car loop, which just goes forward to a tunnel, disappears and then redoes the loop

local OrigCF = script.Parent.CFrame
while true do
	while true do
		wait(2)
		for i = 1,150 do
			script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,0,8)	--car goes forward
			wait()
		end

		script.Parent.CFrame = OrigCF
		
	end
end
3 Likes

I would probably start off by not having while true do loops, instead, try having a function that senses when a player is pressing the forward key/button.

1 Like

it has to be a loop because its essentially just a car endlessly going forward into a tunnel, respawning then re-doing that. its like a npc car

its not a player controlling it

The question is unclear, but to my understanding, if you want to make a model travel as a decoration, I suggest using either TweenService service, LinearVelocity constraint, or rig the car to be animate-able and loop the animation so it will run indefinitely.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.