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

How to script Position.Magnitude in an if statement?

What I'm trying to do is that if the car goes forward, it goes back to it's normal speed and when it goes in reverse, it changes the value.

local seat = script.Parent
local car = seat.Parent
local M = seat.Position.Magnitude

local LD = car.RL.WheelMount.Drive
local RD = car.RR.WheelMount.Drive
local LS = car.FL.SpringMount.Steer
local RS = car.FR.SpringMount.Steer

local MS = seat.Speed.Value
local SA = seat.Angle.Value

local function onChanged(property)
	if property == "Throttle" then
		LD.AngularVelocity = MS * seat.Throttle
		RD.AngularVelocity = -MS * seat.Throttle
	end
	if property == "Steer" then
		LS.TargetAngle = SA * seat.Steer
		RS.TargetAngle = SA * seat.Steer
	end
	if M > 1 then
		MS = 77
	end
	if M < 1 then
		MS = 30
	end
end
seat.Changed:Connect(onChanged)

1 answer

✓ Accepted answer

i have no idea where you got the idea that you needed to use Position.Magnitude for this, but you can just check the throttle of the seat instead

local function onChanged(property)
    if property == "Throttle" then
        LD.AngularVelocity = MS * seat.Throttle
        RD.AngularVelocity = -MS * seat.Throttle
	if seat.Throttle >= 0 then
		MS = 77
	else
		MS = 30
	end
    end
    if property == "Steer" then
        LS.TargetAngle = SA * seat.Steer
        RS.TargetAngle = SA * seat.Steer
    end
end

1 comment

0

It worked, but it didn't changed the NumberValue's value

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