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

How to change a NumberValue's value?

I want to change a NumberValue's value whenever the car goes backwards and forwards.

The NumberValue

local MS = seat.Speed.Value

The function that has to change the NumberValue's value.


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
			print("going forward")
		else
			MS = 30
			print("going backward")
		end
	end
	if property == "Steer" then
		LS.TargetAngle = SA * seat.Steer
		RS.TargetAngle = SA * seat.Steer
	end
end
seat.Changed:Connect(onChanged)

1 answer

✓ Accepted answer

You do


seat.Speed.Value = 50 -- Can be any value

If you store the value into a variable, it only stores the number not the actual instance, you have to do NumberValue.Value = 30 not MS = 30

3 comments

0

So do I have to remove the MS variable?

0

It worked, but it didn't change the cars' speed

0

nvm, I managed to fix it

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