Large Model Movement?

I want to make a moving road that is 250 studs. The player is inside a bus to make the illusion of the bus moving.

Whenever I do this using:
X=script.Parent

while true do
wait()
for i= 1, 50 do
X:TranslateBy(Vector3.new(0, 0, -0.5))
wait()
end
for i= 1, 1 do
X:TranslateBy(Vector3.new(0, 0, 25))
wait()
end
end

There are too many parts and it gets laggy. How can I not make it laggy?

I’ve tried looking for the answer here and on youtube and found nothing. Maybe It could be that just the bus moves but then there would have to be a script that doesn’t make the player slide off every time it moves.

You can try use Model:SetPrimaryPartCFrame. But for that your model will need have a PrimaryPart.

so
while true do
Model:SetPrimaryPartCFrame
end

?

Yea but you might add a wait on your loop. Like 1 second.

Make a wait(1) maybe thats gonna move part for 1 sec but you can change it to .5 too

while true do
script.Parent:SetPrimaryPartCFrame
wait (0.4)
end

i used this, i dont know why but it didnt work.

You need define CFrame.

script.Parent:SetPrimaryPartCFrame(CFrame.new())

You gotta calculate the CFrame to make it work. Example:

local PrimaryPart = script.Parent.PrimaryPart
local CF = CFrame.new(PrimaryPart.Position.X,PrimaryPart.Position.Y,PrimaryPart.Position.Z) + Vector3.new(0,0,5)
script.Parent:SetPrimaryPartCFrame(CF)

You’re not using SetPrimaryPartCFrame() properly.

local run = game:GetService("RunService")
local origin = script.Parent.PrimaryPart.CFrame
local direction = Vector3.new(0, 0, 1)
local rate = 1 -- studs/second
local start = time()
while true do
    local t = time() - start
    script.Parent:SetPrimaryPartCFrame(origin + (direction.Unit * t * rate))
    run.Stepped:Wait()
end

Or alternatively, instead of using the while-loop:

run.Stepped:Connect(function()
    local t = time() - start
    script.Parent:SetPrimaryPartCFrame(origin + (direction.Unit * t * rate))
end)
1 Like

ok this works but how can i change the speed it does it at? Changing wait time is possible but if i set it to 0.00000000000000000000000000000000000000000000000000005 it still goes slowly

Just change the vector3 in this line:

local CF = CFrame.new(PrimaryPart.Position.X,PrimaryPart.Position.Y,PrimaryPart.Position.Z) + Vector3.new(0,0,5) -- Change the 5 to what number you want.

OH THANKSSS but how can i make it go to a coordinate every 50 studs or so, i know how to make it go to a coordinate but how do i add a wait to it

If you need to make it start and stop at specific locations instead of move constantly you might want to use TweenService

oh also, how can i add the smoothness? like i want it at 60 studs per second but make it smooth so it doesnt just look laggy.

nvm now im back to my original problem. it just looks laggy.


looked fine in run but when i play it its laggy

The Stepped event of RunService fires once every frame in the server’s physics simulation. Assuming you haven’t changed other parts of the script (like adding a wait(1) where there shouldn’t be) it might be the lag from the game itself, not the script.

The reason it looks laggy is because you’re probably animating it on the server, not the client. No matter how well you animate it on the server, it’s going to look stuttery, because the network is not perfectly consistent, some packets of information take slightly longer or shorter times to arrive, or even occasionally get lost and have to be resent doubling the delay.

Basically, you have to do this from a localscript for it to work well.

2 Likes