The problem is that you're trying to set the CFrame of the model to a Vector3. This doesn't work since CFrames have additional properties besides a Vector3 position.
However, you can create a CFrame from a Vector3 using CFrame.new. NOTE: by default, this will set the CFrame's orientation to 0,0,0.
local model = game.Workspace.Car
local originallocation = model.PrimaryPart.CFrame
while true do
for i = 0,100,0.1 do
model:SetPrimaryPartCFrame(CFrame.new(model.PrimaryPart.Position + Vector3.new(1,0,0)))
wait()
end
model:SetPrimaryPartCFrame(originallocation)
end
Changing the rotation is quite simple. The CFrame.Angles function will modify the orientation of any other CFrame, by simply multiplying both of them together.
CFrame.new(0,0,0) * CFrame.Angles(0,90,0)
But keep in mind that this function expects the inputs to be in radians, not in degrees. So the rotation might seem a bit, off. But fortunately there's a function that converts degrees into radians, as well as a function which does the opposite. It's math.rad and math.deg.
math.rad expects an input in degrees and converts it into an output in radians, which is exactly what we want.
CFrame.new(0,0,0) * CFrame.Angles(math.rad(0),math.rad(90),math.rad(0))
Here's your script but with the changes:
local model = game.Workspace.Car
local originallocation = model.PrimaryPart.CFrame
while true do
for i = 0,100,0.1 do
model:SetPrimaryPartCFrame(CFrame.new(model.PrimaryPart.Position + Vector3.new(1,0,0)) * CFrame.Angles(math.rad(0),math.rad(90),math.rad(0)) )
wait()
end
model:SetPrimaryPartCFrame(originallocation)
end
You'll have to play around with the values to find the correct orientation.
2 comments
Thank you, it works but the car rotated, where would I change the rotation
I edited my post to consider this as well.