Local script wont work after model gets regenerated

This the Local 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(5)
	vehicle:SetPrimaryPartCFrame(vehicle.PrimaryPart.CFrame * CFrame.new(-0.1, 0.05,0  * dt))
	wait(5)
	vehicle:SetPrimaryPartCFrame(vehicle.PrimaryPart.CFrame * CFrame.new(-0.1,0,0  * dt))
	end)

And this is the model regenerate Server Script:

object = script.Parent

if (object ~= nil) and (object ~= game.Workspace) then

model = object

backup = model:clone()

waitTime = script.Parent.Time.Value

wait(1)

while true do

wait(waitTime+2)

model:remove()

model = backup:clone()

wait(2)

model.Parent = game.Workspace

model:makeJoints()

end

end

For some reason the local script wont work when the model get regenerated and theres no error messages.

I think it is because

this line only run once when the script started so put that line in the Heartbeat event.

Any solution of how can i run it every time?

Remove your local and just reference the model in workspace. Like

game:GetService("RunService").Heartbeat:Connect(function(dt)

	game.Workspace.Robbery.SubmarineExterior:SetPrimaryPartCFrame(game.Workspace.Robbery.SubmarineExterior.PrimaryPart.CFrame * CFrame.new(-0.1, 0,0  * dt))
	wait(5)
	game.Workspace.Robbery.SubmarineExterior:SetPrimaryPartCFrame(game.Workspace.Robbery.SubmarineExterior.PrimaryPart.CFrame * CFrame.new(-0.1, 0.05,0  * dt))
	wait(5)
	game.Workspace.Robbery.SubmarineExterior:SetPrimaryPartCFrame(game.Workspace.Robbery.SubmarineExterior.PrimaryPart.CFrame * CFrame.new(-0.1,0,0  * dt))
	end)