local Z=Effects.new(ChassisModel,EffectsFolder,TopModel)VehicleSeating.SetRemotesFolder(RemotesFolder)VehicleSeating.SetBindableEventsFolder(BindableEventsFolder)local Q=nil local A=Chassis.GetDriverSeat()local F=Chassis.GetPassengerSeats()local b={"\082\105\103\104\116\070\111\111\116","\082\105\103\104\116\076\111\119\101\114\076\101\103";"\076\101\102\116\070\111\111\116";"\076\101\102\116\076\111\119\101\114\076\101\103"}local q={"\066\111\100\121\066\097\099\107\065\116\116\097\099\104\109\101\110\116","\087\097\105\115\116\066\097\099\107\065\116\116\097\099\104\109\101\110\116";"\072\097\116\065\116\116\097\099\104\109\101\110\116"}local function U(Z,Q)if Z:IsA("\072\117\109\097\110\111\105\100")then Z=Z.Parent elseif Z:IsA("\080\108\097\121\101\114")then Z=Z.Character end for Z,A in ipairs(Z:GetChildren())do if A:IsA("\065\099\099\111\117\116\114\101\109\101\110\116")then local Z=A:FindFirstChild("\072\097\110\100\108\101")if Z then local A=false for Q,F in ipairs(q)do if Z:FindFirstChild(F)then A=true end end if A then Z.Transparency=Q end end end end for A,F in ipairs(b)do local b=Z:FindFirstChild(F)if b then b.Transparency=Q end end end local function N(F,b)if F:IsA("\080\108\097\121\101\114")then RemotesFolder.ExitSeat:FireClient(F,false)local Z=F:FindFirstChildOfClass("\080\108\097\121\101\114\071\117\105")if Z then local Q=Z:FindFirstChild(UniqueName.."\095\067\108\105\101\110\116\067\111\110\116\114\111\108\115")if Q then Q:Destroy()end end end U(F,0)if F:IsA("\072\117\109\097\110\111\105\100")then F.Sit=false end if Q then Q:Disconnect()Q=nil end if b==A then A:SetNetworkOwnershipAuto()Chassis.Reset()Z:Disable()end end local function n(F,b)if b and b.Occupant then local Z=true local Q=TopModel:GetAttribute("\084\097\107\101\079\102\102\065\099\099\101\115\115\111\114\105\101\115")if Q~=nil then Z=Q end if Z then U(b.Occupant,1)end end if not F:IsA("\080\108\097\121\101\114")then return end local q=F:FindFirstChildOfClass("\080\108\097\121\101\114\071\117\105")if q then local U=Instance.new("\083\099\114\101\101\110\071\117\105")U.Name=UniqueName.."\095\067\108\105\101\110\116\067\111\110\116\114\111\108\115"U.ResetOnSpawn=true U.Parent=q Q=F.CharacterRemoving:Connect(function()N(F)end)local n=LocalGuiModulePrototype:Clone()n.Parent=U if b==A then local Q=DriverScriptPrototype:Clone()Q.CarValue.Value=TopModel Q.Parent=U Q.Disabled=false A:SetNetworkOwner(F)Z:Enable()else local Z=PassengerScriptPrototype:Clone()Z.CarValue.Value=TopModel Z.Parent=U Z.Disabled=false end local P=Instance.new("\079\098\106\101\099\116\086\097\108\117\101")P.Name="\083\099\114\105\112\116\115\082\101\102\101\114\101\110\099\101"P.Value=Scripts P.Parent=U end end
-- This module is a class with a new() constructor function
local EffectsInstance = Effects.new(ChassisModel, EffectsFolder, TopModel)

VehicleSeating.SetRemotesFolder(RemotesFolder)
VehicleSeating.SetBindableEventsFolder(BindableEventsFolder)

local CharacterRemovingConnection = nil

local DriverSeat = Chassis.GetDriverSeat()
local AdditionalSeats = Chassis.GetPassengerSeats()

local LEG_PARTS_TO_REMOVE = { "RightFoot", "RightLowerLeg", "LeftFoot", "LeftLowerLeg" }
local ATTACHMENTS_TO_REMOVE = { "BodyBackAttachment", "WaistBackAttachment", "HatAttachment" }

local function setHatsAndLegsTransparency(obj, transparency)
	if obj:IsA("Humanoid") then
		obj = obj.Parent
	elseif obj:IsA("Player") then
		obj = obj.Character
	end

	for _, child in ipairs(obj:GetChildren()) do
		if child:IsA("Accoutrement") then
			local handle = child:FindFirstChild("Handle")
			if handle then
				local shouldRemove = false
				for _, attachmentName in ipairs(ATTACHMENTS_TO_REMOVE) do
					if handle:FindFirstChild(attachmentName) then
						shouldRemove = true
					end
				end

				if shouldRemove then
					handle.Transparency = transparency
				end
			end
		end
	end

	for _, legName in ipairs(LEG_PARTS_TO_REMOVE) do
		local legPart = obj:FindFirstChild(legName)
		if legPart then
			legPart.Transparency = transparency
		end
	end
end

local function onExitSeat(obj, seat)
	if obj:IsA("Player") then
		RemotesFolder.ExitSeat:FireClient(obj, false)

		local playerGui = obj:FindFirstChildOfClass("PlayerGui")
		if playerGui then
			local scriptContainer = playerGui:FindFirstChild(UniqueName .. "_ClientControls")
			if scriptContainer then
				scriptContainer:Destroy()
			end
		end
	end

	setHatsAndLegsTransparency(obj, 0)

	if obj:IsA("Humanoid") then
		obj.Sit = false
	end

	if CharacterRemovingConnection then
		CharacterRemovingConnection:Disconnect()
		CharacterRemovingConnection = nil
	end

	if seat == DriverSeat then
		DriverSeat:SetNetworkOwnershipAuto()
		Chassis.Reset()
		EffectsInstance:Disable()
	end
end

local function onEnterSeat(obj, seat)
	if seat and seat.Occupant then
		local ShouldTakeOffHats = true
		local prop = TopModel:GetAttribute("TakeOffAccessories")

		if prop ~= nil then
			ShouldTakeOffHats = prop
		end

		if ShouldTakeOffHats then
			setHatsAndLegsTransparency(seat.Occupant, 1)
		end
	end

	if not obj:IsA("Player") then
		return
	end

	local playerGui = obj:FindFirstChildOfClass("PlayerGui")
	if playerGui then
		local screenGui = Instance.new("ScreenGui")
		screenGui.Name = UniqueName .. "_ClientControls"
		screenGui.ResetOnSpawn = true
		screenGui.Parent = playerGui

		CharacterRemovingConnection = obj.CharacterRemoving:Connect(function()
			onExitSeat(obj)
		end)

		local localGuiModule = LocalGuiModulePrototype:Clone()
		localGuiModule.Parent = screenGui

		if seat == DriverSeat then
			local driverScript = DriverScriptPrototype:Clone()
			driverScript.CarValue.Value = TopModel
			driverScript.Parent = screenGui
			driverScript.Disabled = false

			DriverSeat:SetNetworkOwner(obj)
			EffectsInstance:Enable()
		else
			local passengerScript = PassengerScriptPrototype:Clone()
			passengerScript.CarValue.Value = TopModel
			passengerScript.Parent = screenGui
			passengerScript.Disabled = false
		end

		local scriptsReference = Instance.new("ObjectValue")
		scriptsReference.Name = "ScriptsReference"
		scriptsReference.Value = Scripts
		scriptsReference.Parent = screenGui
	end
end
