Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Stop Delay for Moving Parts?

Asked by 4 years ago

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.

0
Well you could just change the whole part with Move.Position = Vector3.new(urpos) VitroxVox 884 — 4y
0
The problem with this is that I want the model moving at a constant speed. Such as a car going through a city. BodyPosition will just teleport the model instead. GreatTurkeySandwich 2 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

You have wait() delays in your code. Shorten them and see if it's faster now.

0
Those are there for the model to wait a certain amount of time to change direction. What I mean in my question is that the model is supposed to stop at a certain point. And in-game the model will usually go past that point. GreatTurkeySandwich 2 — 4y
0
Use If Statements to make sure the part is not pasted it's point. ViviTheLuaKing 103 — 4y
0
That makes perfect sense to me, but I can't seem to implement them without the script breaking. GreatTurkeySandwich 2 — 4y
0
Shorten the Vector3 values. ViviTheLuaKing 103 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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.

Answer this question