Stopping a Moving Car

I’m looking at making a game where players can practice around for a few minutes on a racetrack before I set them up on the starting line to go race. Rather than deleting the car I’ve spawned them in and spawn a new car, I’m setting the CFrame of their current car & anchoring the tires / vehicleseat to prevent movement. This has the side effect however of preserving their previous momentum, such that when the race starts, their car will jolt forward with it’s previous speed.

Here is the current code I’m using for this task:

 local Players = game:GetService("Players")
	for index, p in pairs(Players:GetChildren()) do
		local cars = workspace.Cars
		local currentCar = cars:FindFirstChild(p.Name.."Car")
		if currentCar ~= nil then
			local track = workspace:WaitForChild("Track")
			currentCar:SetPrimaryPartCFrame(track.StartSpots:FindFirstChild("P"..curCar).CFrame)
			curCar = curCar + 1
			for index, child in pairs(currentCar:GetChildren()) do
				if child:IsA("Part") or child:IsA("WedgePart") or child:IsA("VehicleSeat") then
					PhysicsService:SetPartCollisionGroup(child, playersno)
					if child.Name == "Tire" or child.Name == "VehicleSeat" then
						child.Anchored = true
					end
				end
			end	
		end	
	end

Here’s also a video of what happens:

So far, I haven’t been able to really think of what to do to stop this from happening, hence my turning to the forum for possible suggestions.

1 Like

Try setting the mph value of the car to 0, from what I can see the “engine’s output” is still the same as it was when the tires weren’t anchored.

1 Like

Figured out my own solution.
When looping through the car, you can just set the velocity of all parts to 0.

child.Velocity = Vector3.new(0,0,0)
1 Like