I've made a script where a part or model will move to an exact spot, then move to another one at a constant speed. This works fine in studio, but in-game the model changes path prematurely or too late.
Move = script.Parent Movevelocity = Move.BodyVelocity while true do wait(1) Movevelocity.velocity = Vector3.new(0,0,14) wait(4.3) Movevelocity.velocity = Vector3.new(-14,0,0) wait(12.1) Movevelocity.velocity = Vector3.new(0,0,14) wait(9.15) Movevelocity.velocity = Vector3.new(-14,0,0) wait(10) end
I'm using a BodyVelocity with the script. Lag or memory usage doesn't seem to be the problem. Can anyone help me figure out what's going wrong?
Thanks.
You have wait()
delays in your code. Shorten them and see if it's faster now.
To achieve what you're trying to do, you can instead use TweenService
. It will be much smoother and less delayed. The only thing you have to worry about is to make sure the BasePart is Anchored
local TweenService = game:GetService("TweenService") local Move = script.Parent -- Movevelocity = Move.BodyVelocity (Remove the body velocity) while true do wait(1) TweenService:Create(Move, TweenInfo.new(1), {Position = Vector3.new(0,0,14)}):Play() wait(1) TweenService:Create(Move, TweenInfo.new(4.3), {Position = Vector3.new(-14,0,0)}):Play() wait(4.3) TweenService:Create(Move, TweenInfo.new(12.1), {Position = Vector3.new(-14,0,0)}):Play() wait(12.1) TweenService:Create(Move, TweenInfo.new(9.15), {Position = Vector3.new(0,0,14)}):Play() wait(9.15) TweenService:Create(Move, TweenInfo.new(10), {Position = Vector3.new(0,0,14)}):Play() wait(10) end
Just make sure to edit the position and timing and you should get the results you want.