Distance increases while in a VehicleSeat

I’m making a driving game and I need the player’s distance to increase only while they are driving.
Ignore all the comments, they’re just for notations.

if Humanoid.Sit and Humanoid.SeatPart:IsA("VehicleSeat") then
	wait() -- this is the wait() i mentioned in Core
	print("player is sat")
	while UIS:IsKeyDown(Enum.KeyCode.W) do
		print("w key down")
		--if Humanoid.SeatPart.CarOwner.Value == Player.Name then
			wait(Core.DISTANCE_CHANGE_INTERVAL)
			Leaderstats.Distance.Value = Leaderstats.Distance.Value + 1
		--end
	end
end

I’m aware there’s a more efficient way to check if a player is going forward, but I haven’t got to that yet.
Basically, none of my print statements are calling, and the script isn’t doing what it needs to do.
Probably related, but there’s an error that returns when I first join the game

Players.RhysFaber.PlayerScripts.MileageHandler:10: attempt to index nil with 'Sit'

I don’t see why this returns, as I use yielding calls on everything in the ancestry path of Humanoid.

try using occupant instead since it is more faster and less space to write in, also you can instead get a constantly saving variable of the player’s root part velocity and doing some computations to convert it to a distance value

oh right also the part of the problem is that since the player always loads in before the character, its safe to say the playerScript will be likely to fire before the humanoid loads so you may need to do some adjusting henceforth “attempt to index nil with sit”

like inserting the script inside in the playerCharacter scripts

Only problem with that is that there are multiple cars, so I don’t really have a way to get the occupant of each individual seat, if you understand what I mean. It’s easier to do Humasnoid.SeatPart, granted it might be slower.

that explains some origin conceptions, you can stay with the “humanoid.Sit” and seatpart whatever but one issues you have not preemptively solved yet is that there is no break in the while loop if the player ejects out of sitting position

Thanks for bringing that up, I’ve added

        if not Humanoid.Sit then
			break
		end

to the while loop