Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

i messed up the Event trigger for the PropertyChange of my car seat. Why isn't my car moving?

Asked by
MSDLF -17
5 years ago

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.

0
Don't forget to accept my answer if it works z User#24403 69 — 5y
0
Edited my answer hopefully it explains a bit better User#24403 69 — 5y
0
Please accept my answer if it worked. User#24403 69 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

You're not connecting the functions themselves. You're merely giving the functions a parameter; a functions input variables.

object:GetPropertyChangedSignal("Throttle"):Connect(onActivated)
object:GetPropertyChangedSignal("Steer"):Connect(Steer)

This connects the functions.

Pretty much what you were doing is connecting up a function literal:

object:GetPropertyChangedSignal("Throttle"):Connect(function(onActivated)

end)

onActivated is merely a parameter to the function. You're not connecting the onActivated function itself. You made the same mistake for the steer.

object:GetPropertyChangedSignal("Throttle"):Connect(onActivated)

This connects the onActivated function itself.

Hope I cleared it up better.

0
i don't get it MSDLF -17 — 5y
0
put onActivated() and Steer() within the function itself not as a parameter DinozCreates 1070 — 5y
0
Accepted the answer; please for future reference @MSDLF if an answer answered your question accept it. TheeDeathCaster 2368 — 5y
Ad

Answer this question