How to loop with Cframe position on a touched event?

I can’t seem to find on the forum how to use loops to change the Cframe in terms of position, if someone can provide me with just a few lines of code of how this can be done? I’ve seen examples of this with angles but not position, and Cframe is not a strong point of mine, FYI its gonna be a touched event on an invisible CanCollide false part, and it should stop at a certain place, but I’ve recently heard about something called lerping, is this an option?

By the way, this is a model, a car to be specific

1 Like

lerp to cframe and doing loop on cframe is actually the same thing lets say you want to move your model (Must have a primaryPart)

Method 1: Lerp

 local Model = script.Parent
for i = 0 , 1,  0.1 do
	wait()
	Model.PrimaryPart.CFrame  = Model.PrimaryPart.CFrame:Lerp(CFrame.new(0,0,0), i)
end

its difficult to lerp model in my opinion

Method 2 CFrame:

actually when looping CFrame its difficult to loop where the position you want it here is an example of a model cframe looping to a certain position

local Model = script.Parent
Model.PrimaryPart.CFrame = CFrame.new(0,0,0)
repeat wait(1) Model.PrimaryPart.CFrame = Model.PrimaryPart.CFrame*CFrame.new(1,0,0) until Model.PrimaryPart.CFrame == CFrame.new(10,0,0)

yea i can say that lerping is better but try using Tween Service

2 Likes

Thanks, by the looks of it already, this should work for me, I’ll try it out, and if it does I’ll give a solution.

Tweening is hard in my situation because of the models I’m using, when it comes to having to unanchor everything except primary part and weld constraints and all that, it’s complicated with cars but thanks for the help👊

1 Like

Hmmm, none of the scripts are working for some reason.

You don’t have to, but could you by chance make it to a touched event?

Maybe SetPrimaryPartCFrame would work?

Uhh, Still need help here…

I watched a DevKing video about lerping and I may be able to twist it for models and into a touched event

If I may, what exactly are you trying to accomplish?