How do i fix vehicleseat causing low fps en low memory devices

Im working on a train game and driving causes a lot of fps drop and idk how to fix that i tried almost all and still causes alot of lag

Can we get a code of your “train handler”?

local seat = script.Parent:FindFirstChildWhichIsA(“VehicleSeat”)
if not seat then
warn(“No se encontró VehicleSeat”)
return
end

– Ajustar la fricción para evitar rebotes
for _, part in ipairs(script.Parent:GetDescendants()) do
if part:IsA(“BasePart”) then
part.CustomPhysicalProperties = PhysicalProperties.new(
1, – Densidad
0.5, – Fricción baja para curvas suaves
0, – Elasticidad
1, – Peso de fricción
1 – Peso de elasticidad
)
end
end

– Función para actualizar las ruedas
local function updateWheels()
for _, obj in ipairs(script.Parent:GetDescendants()) do
if obj:IsA(“HingeConstraint”) and obj.ActuatorType == Enum.ActuatorType.Motor then
local wheel = obj.Parent
if wheel:IsA(“BasePart”) then
local relative = seat.CFrame:pointToObjectSpace(wheel.Position)
local isLeft = relative.X < 0
local direction = isLeft and 1 or -1

			obj.AngularVelocity = seat.Throttle * 65 * direction
			obj.MotorMaxTorque = 100000 -- Alto pero realista
		end
	end
end

end

– Conexión a entrada
seat:GetPropertyChangedSignal(“Throttle”):Connect(updateWheels)

– Frenado cuando se baja
seat:GetPropertyChangedSignal(“Occupant”):Connect(function()
if not seat.Occupant then
for _, obj in ipairs(script.Parent:GetDescendants()) do
if obj:IsA(“HingeConstraint”) and obj.ActuatorType == Enum.ActuatorType.Motor then
obj.AngularVelocity = 0
end
end
end
end)

– Llamar una vez al inicio
updateWheels()

2 Likes

this is the other one

local seat = script.Parent:FindFirstChildWhichIsA(“VehicleSeat”)
if not seat then
warn(“No se encontró VehicleSeat”)
return
end

– Ajustar la fricción localmente (modelo donde está el script)
for _, part in ipairs(script.Parent:GetDescendants()) do
if part:IsA(“BasePart”) then
part.CustomPhysicalProperties = PhysicalProperties.new(1, 0.5, 0, 1, 1)
end
end

– Actualizar las ruedas locales
local function updateWheels()
for _, obj in ipairs(script.Parent:GetDescendants()) do
if obj:IsA(“HingeConstraint”) and obj.ActuatorType == Enum.ActuatorType.Motor then
local wheel = obj.Parent
if wheel:IsA(“BasePart”) then
local relative = seat.CFrame:pointToObjectSpace(wheel.Position)
local isLeft = relative.X < 0
local direction = isLeft and 1 or -1
obj.AngularVelocity = seat.Throttle * 65 * direction
obj.MotorMaxTorque = 100000
end
end
end
end

– Conexión para cuando se siente un jugador
seat:GetPropertyChangedSignal(“Occupant”):Connect(function()
local occupant = seat.Occupant
if occupant then
local character = occupant.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if not player then return end

	local CurCar = game.Workspace:FindFirstChild(player.Name .. "sCar")
	if not CurCar then
		warn("No se encontrĂł el tren del jugador.")
		return
	end

	-- Dupla1: activar motores
	local dupla1 = CurCar:FindFirstChild("Dupla1")
	if dupla1 then
		local bogie1 = dupla1:FindFirstChild("BogieMotriz")
		if bogie1 then
			for _, part in ipairs(bogie1:GetDescendants()) do
				if part:IsA("HingeConstraint") and part.ActuatorType == Enum.ActuatorType.Motor then
					part.MotorMaxTorque = 20000
					part.MotorMaxAcceleration = 500000
				end
			end
		end
	end

	-- Dupla2: desactivar motores
	local dupla2 = CurCar:FindFirstChild("Dupla2")
	if dupla2 then
		local bogie2 = dupla2:FindFirstChild("BogieMotriz")
		if bogie2 then
			for _, part in ipairs(bogie2:GetDescendants()) do
				if part:IsA("HingeConstraint") and part.ActuatorType == Enum.ActuatorType.Motor then
					part.MotorMaxTorque = 0
					part.MotorMaxAcceleration = 0
				end
			end
		end
	end
else
	-- Se bajĂł, frenar ruedas locales
	for _, obj in ipairs(script.Parent:GetDescendants()) do
		if obj:IsA("HingeConstraint") and obj.ActuatorType == Enum.ActuatorType.Motor then
			obj.AngularVelocity = 0
		end
	end
end

end)

– Detectar cambio de acelerador
seat:GetPropertyChangedSignal(“Throttle”):Connect(updateWheels)

– Llamar al inicio
updateWheels()

2 Likes