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

Workspace.Model.VehicleSeat.Script:35: attempt to call field 'Changed' (a userdata value)?

Asked by 5 years ago

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!

0
Don't name your functions like "yes" or "lol". Name them like(for your code's sake) "OnChanged" or "ChangeProperties". saSlol2436 716 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

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 
0
Wow thanks! ieatandisbaconhair 77 — 5y
0
Wow thanks! ieatandisbaconhair 77 — 5y
Ad

Answer this question