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

Changed not updating properly?

I'm trying to make a car with constraints, but roblox's acceleration and torque cant be changed separatedly, so if a car has too low of an acceleration it wont be able to drive over steep angles. And to fix that im lowering torque as the speed increases, and to do that I used Changed on the vehicle seat (which has a velocity property inside)But it only seems to update when I steer the vehicle. Here is some code to demonstrate what im trying to do.

local function onChanged(property)
if seat.Velocity.magnitude > 40 and seat.Velocity.magnitude < 70 then	

print"fast"

elseif seat.Velocity.magnitude > 70 then	

print "very fast"

else
		
print"slow"
end
end
seat.Changed:connect(onChanged)

There are no errors.

If there is a better way to do this it will also help.

1 answer

✓ Accepted answer

"Changed" often doesn't fire for things that might change continuously. Consider putting the code into a loop like this:

function Start()
	running = true
	coroutine.resume(coroutine.create(function()
		while running do
			--check Velocity here
			wait()
		end
	end))
end
function Stop()
	running = false
end
Start()
--At some point you might want to call Stop() to stop the update loop.

You can get up to 60 updates/sec by using one of the RunService's events.

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