Cant stop model from moving when i use HeartBeat

I am trying make a moving model using cframe and heartbeat(Makes it smoother) but the problem is it wont stop moving this is the script:

local vehicle = game.Workspace.Robbery.SubmarineExterior

game:GetService("RunService").Heartbeat:Connect(function(dt)
	vehicle:SetPrimaryPartCFrame(vehicle.PrimaryPart.CFrame * CFrame.new(-0.1, 0,0 * dt))
	wait(10)
	vehicle:SetPrimaryPartCFrame(vehicle.PrimaryPart.CFrame * CFrame.new(0,0,0)) 
end)

This should stop it from moving after 10 seconds.

local movement = game:GetService("RunService").Heartbeat:Connect(function()
	vehicle:SetPrimaryPartCFrame(vehicle.PrimaryPart.CFrame * CFrame.new(-0.1, 0, 0)
end)

wait(10)
movement:Disconnect()

Though if you want it to move a specific distance, or from one specific location to another specific location you should probably use a tween instead.

after it gets disconnected can it wait for certain amount of time then starts moving again?

Yes you could just repeat that code or wrap it in a loop.

theres an error

Sorry, I forgot to add the closing parenthesis for SetPrimaryPartCFrame

still wont work 30 characters…

Seriously look at the code you posted. You have two connections to RunService.Heartbeat and one of them isn’t needed.

heres the code but still wont work:

local vehicle = game.Workspace.Robbery.SubmarineExterior

local movement = game:GetService("RunService").Heartbeat:Connect(function()

vehicle:SetPrimaryPartCFrame(vehicle.PrimaryPart.CFrame * CFrame.new(-0.1, 0, 0))

end)

wait(10)

movement:Disconnect()

oh never mind it was because the 0.1

Are you getting any error messages? What is the context of this script? Is vehicle being found and does it have a PrimaryPart? “It doesn’t work” isn’t useful at all because there is nothing wrong with the syntax of the code.

Edit: Sorry, haven’t realized you already solved it.

sorry 0.1 was too small as a number for the model