Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

0

Don't forget to accept my answer if it works z

0

Edited my answer hopefully it explains a bit better

0

Please accept my answer if it worked.

1 answer

✓ Accepted answer

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.

4 comments

0

i don't get it

0

put onActivated() and Steer() within the function itself not as a parameter

0

Accepted the answer; please for future reference @MSDLF if an answer answered your question accept it.

This discussion is preserved as it was. New answers, comments, and votes are closed.