Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

1 comment

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.