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.
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)
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
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.
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.