Door System breaking everytime regened the vehicle

Hi, I am trying to make a vehicle that uses A-Chassis with openable and functioning doors. But I have some problem with it with the regen feature on the vehicle.

When I regen the vehicle more than 1 time, the door system breaks (The door does not open nor close when I click it) . I am unsure of what’s causing this because there are no errors on the console.
I also tried to make it so that whenever I regen the vehicle, the vehicle model position gets moved to a part called “PositionHolder”. It only does it once and it brings it somewhere else.
ezgif.com-crop

There are multiple scripts of the door system so I’ll just link the rbxm here for more context
sample.rbxm (775.9 KB)
(The door thingy is on Body.Misc and inside all the hatches.)

I’ve tried looking for solutions but I didn’t find any
Thanks in advance!

Are the doors being Welded to the chassis when it gets regened?
Is the script referencing the old doors, or is the script that opens and closes them resetting the doors to the current vehicle?

I’m not sure, but I think this has to do something with the door being welded to the chassis when it gets regened. Though the doors work the first time before I regen it.

From what I understand the A-Chassis has all Anchored Parts and has a weld script that joins them.
You may have to put the doors in a separate model, meaning you have a model for your car that contains a model of the doors, and the model of the A-Chassis.
This should keep the doors from being welded to the chassis.
You’d need to keep all the door Parts unanchored and use WeldConstraints to hold them together, but make sure your HingeConstraints for the doors are attached to Attachments in the A-Chassis.

Alright, I’ll try that and let you know how it goes thanks

Not sure why the door issue happens (probably lacks explanation) but I assume the reason why it brings the vehicle somewhere else is because you’re setting the position of PositionHolder instead of the CFrame, and if you have any weld constraints it’s gonna mess everything up. I recommend simply setting the CFrame, you can get the exact same result while avoiding that issue

I tried putting the hatch models outside of the misc, but still inside the vehicle model and unanchored all of them, putting weld constraints to all door parts. I still can’t open nor close it.

I’m unsure if I’m doing it correctly given how my scripting skills aren’t that good, but I think I did something wrong or didn’t follow correctly because the same result happens.

Here’s the modified code

local Vehicle = script.Parent["M1151A1 (O-GPK/M2)"]:Clone()
local posholder = script.Parent.PositionHolder
local primpart = Vehicle.Body.PRIMARY
local currentCF = Vehicle:GetPivot()



function AbleAll(vehicle, able)
	for _, v in pairs(vehicle:GetDescendants()) do
		if v:IsA("BasePart") then
			v.Anchored = not able
		end
	end
end

AbleAll(Vehicle, true)

local CurrentVehicle = script.Parent["M1151A1 (O-GPK/M2)"]

local Regen = script.Parent.Regen
local ClickDetector = Regen.ClickDetector
local Display = script.Parent.Table.TextStuff.BillboardGui.TextLabel
local InUse = false
local Debounce = false

function UpdateUse()
	Display.Text = Debounce and "REGENERATING" or InUse and "VEHICLE IS IN USE" or "REGEN"
end

function HandleVehicle(vehicle)
	InUse = false
	local seats = {}

	local function CheckUse()
		local used = false
		for _, occupied in pairs(seats) do
			if occupied then
				used = true
				break
			end
		end
		InUse = used
		UpdateUse()
	end

	local function GetAllSeats(vehicle)
		for _, v in pairs(vehicle:GetDescendants()) do
			if v:IsA("VehicleSeat") or v:IsA("Seat") then
				local id = #seats + 1
				seats[id] = false
				v.ChildAdded:Connect(function(child)
					if child.Name == "SeatWeld" then
						seats[id] = true
						CheckUse()
					end
				end)
				v.ChildRemoved:Connect(function(child)
					if child.Name == "SeatWeld" then
						seats[id] = false
						CheckUse()
					end
				end)
			end
		end
	end

	GetAllSeats(vehicle)
end

HandleVehicle(CurrentVehicle)

ClickDetector.MouseClick:Connect(function()
	if not InUse and not Debounce then
		Debounce = true
		UpdateUse()
		CurrentVehicle:Destroy()
		task.wait(3)
		CurrentVehicle = Vehicle:Clone()
		CurrentVehicle.Parent = script.Parent
		CurrentVehicle.PrimaryPart = primpart
		CurrentVehicle:SetPrimaryPartCFrame(CFrame.new(posholder.CFrame.Position))
		CurrentVehicle:SetPrimaryPartCFrame(CFrame.new(CurrentVehicle.PrimaryPart.CFrame.Position, CurrentVehicle.PrimaryPart.CFrame.Position + primpart.CFrame.LookVector) + Vector3.new(0, 2, 0))
		CurrentVehicle:MakeJoints()
		AbleAll(CurrentVehicle, false)
		HandleVehicle(CurrentVehicle)
		wait(5)
		Debounce = false
		UpdateUse()
	end
end)

I managed to fix the position not being moved by removing the line that sets the primarypart.
But the issue of the door remains still

ClickDetector.MouseClick:Connect(function()
	if not InUse and not Debounce then
		Debounce = true
		UpdateUse()
		
		local NewVehicle = Vehicle:Clone()
		NewVehicle.Parent = script.Parent
		
		NewVehicle:SetPrimaryPartCFrame(CFrame.new(posholder.CFrame.Position) + Vector3.new(0, 2, 0))
		NewVehicle:MakeJoints()
	
		CurrentVehicle:Destroy()
		CurrentVehicle = NewVehicle
		
		AbleAll(CurrentVehicle, false)
		HandleVehicle(CurrentVehicle)
		
		wait(5)
		Debounce = false
		UpdateUse()
	end
end)

I’ve managed to fix the door problem aswell by cloning the motor script and deleting the old one in the regen script. Thank you guys for helping.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.