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

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

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!

1 comment

0

Don't name your functions like "yes" or "lol". Name them like(for your code's sake) "OnChanged" or "ChangeProperties".

1 answer

✓ Accepted answer

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 

2 comments

0

Wow thanks!

0

Wow thanks!

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