How can i temporary stop a car from moving without destroying the chassis?

Basically, i have a customer asking for a race system, overall it works fine but they car can move while the start countdown is going, is there a way to prevent that temporary?

4 Likes

Have you tried anchoring it or setting the car speed to 0?

3 Likes

anchoring might break the welds when unanchoring the car.

1 Like

might. but have you tested it?

yea and we have an interesting error

When I anchor my cars, and then unanchor them, the welds get disabled until the car is unanchored, and then when the car is unanchored, the welds are re-enabled, and the car works just fine.

even if its not a weld issue its a networking issue

Do you have the full script with this code, and if so, would you mind sharing it? I know exactly what the issue is.

I can’t give you the full code, its over 500 lines lol

local cartp = workspace.Races:FindFirstChild(racedata.Name).CarTp

		for _, vehicle in vehicles do

			vehicle:MoveTo(cartp.Position + Vector3.new(0,5,0))
			vehicle:PivotTo(cartp.CFrame)

			local driver = game.Players:GetPlayerByUserId(vehicle:GetAttribute("Racer"))

			if not driver then
				print("No driver")
			end

			if driver then
				task.spawn(function()
					wait(0.1)

					local driverseat = false

					for _, part in vehicle:GetDescendants() do
						if part:IsA("VehicleSeat") then
							driverseat = part
						end
					end

					-- Continue and presvent leak
					if not driverseat then
						driverseat = nil

						return
					end

					if driverseat then
						driverseat:Sit(driver.Character.Humanoid)

						-- Stop the car from moving

						driverseat = nil
					end
				end)
			end
		end

		-- Multiply earning by amount of players
		local winnerearning = (racedata.Reward * #players)

		wait(4)
		local checkpoints = ServerStorage.Races:FindFirstChild(racedata.Name):FindFirstChild("Checkpoints")

		if not checkpoints then
			warn("The checkpoints are missing broo")
			return
		else 
			checkpoints = checkpoints:Clone()
		end

		-- Setup checkpoints
		checkpoints.Parent = workspace.Races:FindFirstChild(racedata.Name)
		checkpoints:SetAttribute("CurrentRace",racedata.Name)

		-- Start countdown

		for _, player in players do
			task.spawn(function()
				for t = 5,0,-1 do
					ReplicatedStorage.RemoteEvents.SendRaceInformation:FireClient(player,"Race Countdown",t)
					wait(1)
				end
			end)
		end

		wait(5)

		local max = #checkpoints:GetChildren()

		-- Give data the player can collect
		local GivableData = {
			Name = racedata.Name,
			Laps = racedata.Laps,
			CurrentLaps = 1,
			CurrentCheckpoint = 1,
			CurrentPosition = 0,
			NextCheckpoint = 1,
			TotalCheckpoints = max
		}

		-- Send the data to players
		for _,player in players do
			-- Setup the stats
			player:SetAttribute("Checkpoint",0)
			player:SetAttribute("NextCheckpoint",1)
			player:SetAttribute("Laps",1)

			-- Setup the display and give startup data
			ReplicatedStorage.RemoteEvents.SendRaceInformation:FireClient(player,"Show Display",GivableData)
			ReplicatedStorage.RemoteEvents.SendRaceInformation:FireClient(player,"Show Checkpoint",GivableData)
		end

		-- Set a manual time format
		local Time = {
			Minutes = 0,
			Seconds = 0,
			Miliseconds = 0,
		}

		local function SortTime()
			table.sort(players,function(a,b)
				if Times[a.UserId] then

				end
			end)	
		end

		local function HandlePlace(player)
			local Minutes = Time.Minutes
			local Seconds = Time.Seconds
			local Miliseconds = Time.Miliseconds
			local TotalTime = Minutes*60*1000 + Seconds*1000 + Miliseconds

			-- Award the player with time
			Times[player.UserId] = TotalTime

			Minutes = nil
			Seconds = nil
			Miliseconds = nil
			TotalTime = nil

			SortTime()
		end

		-- Release vehicles
		for _, vehicle in vehicles do

			local driver = game.Players:GetPlayerByUserId(vehicle:GetAttribute("Racer"))

			if not driver then
				print("No driver")
			end

			if driver then
				task.spawn(function()
					wait(0.1)

					local driverseat = false

					for _, part in vehicle:GetDescendants() do
						if part:IsA("VehicleSeat") then
							driverseat = part
						end
					end

					-- Continue and presvent leak
					if not driverseat then
						driverseat = nil

						return
					end

					if driverseat then
						-- Where it should release
						
						driverseat = nil
					end
				end)
			end
		end

This issue is that in line 143 where the error is happening, the script is running DriverSeat:SetNetworkOwner(obj) on an anchored assembly. Normally this code won’t error, but if the car is anchored, this line of code will error. If I had a copy of the whole script, I would have a much better solution to this problem, but since I don’t, one simple solution is to add this block of code right before running that line of code:

while DriverSeat.Anchored do
    DriverSeat.Changed:Wait()
    if not DriverSeat.Anchored then
        break -- Redundancy to protect against the loop getting stuck.
    end
end
print("Loop didn't get stuck") -- You don't really need this print, unless you are debugging.
DriverSeat:SetNetworkOwner(obj)

What this will do is if the driver seat is anchored, we will run a loop that runs until it gets unanchored, and then once the car is unanchored, the loop will quit running, and the code that is after the loop will run.

A better solution to this would be to connect to the .Changed event that is associated with the Driver’s Seat, and then inside the event, check to see if the Driver’s Seat isn’t anchored. If the Driver’s Seat isn’t anchored, then you set the network owner of the Driver’s Seat to the obj. Then delete the original line of code (line 143) that sets the network owner. Make sure that when you connect to that event, you write the connection to that event such that it will only connect to that event once. If you write this connection right before you set the NetworkOwner, your script will probably connect to that event more than once (Every time that block of code runs, it will connect to it), and that can cause memory leaks, and other strange issues.

1 Like

I’m not sure this would be a good idea, but you could try and parent the chassis to ReplicatedStorage until you want the car to move again.

very bad idea, i want something temporary and this is going to break the chasis.

Not sure how the script works, but it looks a lot like an A-Chassis setup.

When I was using those, I created 4 parts and placed them where they would collide with the wheels.

You can then toggle the CanCollide property on and off to allow the car to move.

It also works great to stop the car when a player jumps out while the car is moving.

I think its just the free model police car that ROBLOX created

Yea the customer requested a multi chassis race system until they get they custom chassis for they game.

If the A-Chassis system leaves the wheels unwelded try Anchoring the wheels instead of the car .