Why is my engine moving the way it shouldn't?

I have a little train thingy here and it moves on really strange tracks for testing purposes.

Here is the code that moves the train:

for i = 1, #tracks:GetChildren(), 1 do
	local nextTrack 
	if i == #tracks:GetChildren() then
		nextTrack = tracks["Track"..1]
		currentTrack = 1
	else
		nextTrack = tracks["Track"..i]
		currentTrack = i
	end
	if nextTrack then
		local attachment = nextTrack.TrackAttachment
		repeat 
			task.wait() 
			local formula = math.round((engine.Position-attachment.WorldPosition).Magnitude)
			print(nextTrack, attachment.WorldPosition)
		until formula <= 5
		prismconst.Attachment0 = attachment --PrismaticConstraint
		prismconst.UpperLimit = nextTrack.Size.Z
		engine.CFrame = attachment.WorldCFrame
		print("attachment position that should be", attachment.WorldPosition, "engine position", engine.Position)
		platform.CFrame = engine.CFrame * CFrame.new(0,1.5,0)
		platform.VehicleSeat.Position = engine.Position + Vector3.new(0,2,0)
	end
end

In the testing track there is approximately 56 track parts, and on the 53-54 it breaks.

Here is what my script prints:
output

And here is what on the server side: (script is a localscript with server running context btw)

Does somebody know how to fix this???

unsure whats going on given you dont show the actual incorrect movement, just a screenshot. a gif or video would be better

1 Like


heres a little video

ok, i checked the code logic and everything seems right

i also checked the attachments position, orientation and where they are facing.
the problem was in the attachments after all: they were facing the wrong way and i positioned them wrong too.

so, guys, double check!