I want to make my car's engine script to respond to events by the seat. Not a while loop. How do i do that?
local car = script.Parent.Parent
local topspeed = car.VehicleSeat.Configuration.TopSpeedLevel.Value
local handling = car.VehicleSeat.Configuration.HandlingLevel.Value
local acceleration = car.VehicleSeat.Configuration.Acceleration.Value
local speed = 150
function Steer()
if script.Parent.Steer == 1 then
car.Axle.SteerHinge.TargetAngle = 5
car.Axle.SteerHinge.ServoMaxTorque = car.Axle.SteerHinge.ServoMaxTorque + (0.1*handling) * car.Axle.SteerHinge.ServoMaxTorque
script.Parent.Parent.Rod.HingeConstraint.TargetAngle = -20
end
if script.Parent.Steer == -1 then
car.Axle.SteerHinge.TargetAngle = -5
car.Axle.SteerHinge.ServoMaxTorque = car.Axle.SteerHinge.ServoMaxTorque + (0.1*handling) * car.Axle.SteerHinge.ServoMaxTorque
script.Parent.Parent.Rod.HingeConstraint.TargetAngle = 20
end
if script.Parent.Steer == 0 then
car.Axle.SteerHinge.TargetAngle = 0
script.Parent.Parent.Rod.HingeConstraint.TargetAngle = 0
car.Axle.SteerHinge.ServoMaxTorque = 2*(car.Axle.SteerHinge.ServoMaxTorque + (0.1*handling) * car.Axle.SteerHinge.ServoMaxTorque)
end
end
function OnActivated()
if script.Parent.Throttle == 1 then
car.Transmission.LeftDrive.MotorMaxTorque = car.Transmission.LeftDrive.MotorMaxTorque + (0.1*acceleration) * car.Transmission.LeftDrive.MotorMaxTorque
car.Transmission.RightDrive.MotorMaxTorque = car.Transmission.RightDrive.MotorMaxTorque + (0.1*acceleration) * car.Transmission.RightDrive.MotorMaxTorque
car.Transmission.LeftDrive.AngularVelocity = speed * (1.1*topspeed) + speed
car.Transmission.RightDrive.AngularVelocity = -(speed * (1.1*topspeed) + speed)
script.Parent.Parent.Throttle.Rot.HingeConstraint.TargetAngle = 20
end
if script.Parent.Throttle == -1 then
car.Transmission.LeftDrive.MotorMaxTorque = car.Transmission.LeftDrive.MotorMaxTorque + (0.1*acceleration) * car.Transmission.LeftDrive.MotorMaxTorque
car.Transmission.RightDrive.MotorMaxTorque = car.Transmission.RightDrive.MotorMaxTorque + (0.1*acceleration) * car.Transmission.RightDrive.MotorMaxTorque
car.Transmission.LeftDrive.AngularVelocity = -(speed * (1.1*topspeed) + speed )
car.Transmission.RightDrive.AngularVelocity = speed * (1.1*topspeed) +speed
script.Parent.Parent.Throttle.Rot.HingeConstraint.TargetAngle = -20
end
if script.Parent.Throttle == 0 then
car.Transmission.LeftDrive.MotorMaxTorque = car.Transmission.LeftDrive.MotorMaxTorque + (0.1*acceleration) * car.Transmission.LeftDrive.MotorMaxTorque
car.Transmission.RightDrive.MotorMaxTorque = car.Transmission.RightDrive.MotorMaxTorque + (0.1*acceleration) * car.Transmission.RightDrive.MotorMaxTorque
car.Transmission.LeftDrive.AngularVelocity = 0
car.Transmission.RightDrive.AngularVelocity = 0
script.Parent.Parent.Throttle.Rot.HingeConstraint.TargetAngle = 0
end
end
local object = script.Parent -- vehicle seat
object:GetPropertyChangedSignal("Throttle"):Connect(function(OnActivated)
end)
object:GetPropertyChangedSignal("Steer"):Connect(function(Steer)
end)
When i try to turn steer or throttle then it won't do anything. I think the problem is with the last 4 lines of code.

3 comments
Don't forget to accept my answer if it works z
Edited my answer hopefully it explains a bit better
Please accept my answer if it worked.