I would like to make a train that moves backwards and forwards forever. I use the script below but the train just stays still. What have I done wrong and how can I fix it?

local Model = script.Parent

while wait() do 
	for i = 0,1,.001 do 
	Model:SetPrimaryPartCFrame(Model:GetPrimaryPartCFrame() * CFrame.new(0,0,-i))
	wait()
	Model:SetPrimaryPartCFrame(Model:GetPrimaryPartCFrame() * CFrame.new(0,0,i))
	wait()
end
end 

6 comments

0

Look at lines 5 and 7. Look at the i and -i

0

try printing the primary parts cframe to see if it does move, but only a little to the point where its barely noticeable

0

I really suggest you use bodyforce, velocity, gyro etc. to make the best user experience.

0

Use TweenService. I use it for my crate drops

0

what's a moving train that doesn't move?

0

It's meant to move but doesn't