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

How to do i make this script c frame backwards to reset its position but really fast?

Asked by 5 years ago

So basically in the script listed below the part moves forward, (its a mesh of a car) then moves backwards to repeat itself. how do I make the process of it Cframing backwards faster?

while true do
wait()
for i= 1, 300 do
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,0,-2)
wait()
end
for i= 1, 300 do
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,0,2)
wait()
end
end

1 answer

Log in to vote
0
Answered by
pidgey 548 Moderation Voter
5 years ago

You can simply use https://developer.roblox.com/api-reference/function/TweenService/Create for smooth and timed results. TweenInfo.new also has a Reverses argument that does exactly what you want.

To do it in your manner, although I highly don't suggest it - you can just double the CFrame it's incrementing the part from script.Parent.CFrame. You will also need to compensate for the loop so it doesn't overshoot.

while true do
wait()
for i= 1, 300 do
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,0,-2)
wait()
end
for i= 1, 150 do
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,0,4)
wait()
end
end

0
Thanks! Adenandpuppy 87 — 5y
Ad

Answer this question