I made a script, that controls a car, but i keep getting Workspace.Model.VehicleSeat.Script:35: attempt to call field 'Changed' (a userdata value). why?
script:
local car = script.Parent.Parent local s = script.Parent local sl = car.steerl local sr = car.steerr local fl = car.FL local rl = car.RL local fr = car.FR local rr = car.RR local stats = s.handling fl.HingeConstraint.MotorMaxTorque = stats.Torque.Value fr.HingeConstraint.MotorMaxTorque = stats.Torque.Value rl.HingeConstraint.MotorMaxTorque = stats.Torque.Value rr.HingeConstraint.MotorMaxTorque = stats.Torque.Value sl.HingeConstraint.ServoMaxTorque = 100000 sr.HingeConstraint.ServoMaxTorque = 100000 local function yes(y) if y == "Throttle" then fl,fr.HingeConstraint.AngularVelocity = stats.TopSpeed.Value * s.Throttle rl,rr.HingeConstraint.AngularVelocity = stats.TopSpeed.Value * -s.Throttle end if y == "Steer" then sl.HingeConstraint.ServoMaxTorque = 100000 sr.HingeConstraint.ServoMaxTorque = 100000 sl.HingeConstraint.AngularSpeed = stats.Handling.Value sr.HingeConstraint.AngularSpeed = stats.Handling.Value sl.HingeConstraint.TargetAngle = stats.SteeringAngle.Value * s.Steer sr.HingeConstraint.TargetAngle = stats.SteeringAngle.Value * s.Steer end end s.Changed(yes)
thanks!
The reason for this is because of line 33. You're attempting to call an event, which will obviously throw an error. You need to call the RBXScriptSignal:Connect()
method on the event
, which will connect yes
.
local function yes(y) if y == "Throttle" then fl,fr.HingeConstraint.AngularVelocity = stats.TopSpeed.Value * s.Throttle rl,rr.HingeConstraint.AngularVelocity = stats.TopSpeed.Value * -s.Throttle elseif y == "Steer" then -- use elseif... sl.HingeConstraint.ServoMaxTorque = 100000 sr.HingeConstraint.ServoMaxTorque = 100000 sl.HingeConstraint.AngularSpeed = stats.Handling.Value sr.HingeConstraint.AngularSpeed = stats.Handling.Value sl.HingeConstraint.TargetAngle = stats.SteeringAngle.Value * s.Steer sr.HingeConstraint.TargetAngle = stats.SteeringAngle.Value * s.Steer end end s.Changed:Connect(yes) -- Connect function