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

My distance traveled script is inaccurate, why?

part = script.Parent

lastPos = part.Position

store = 0

while true do
	local distance = part.Position - lastPos
	lastPos = part.Position
	store = store + distance.Magnitude
	wait()
end


This script does not reflect at all how far the part has moved, based off on another script how fast it is going (the script is on a car)

Not sure why, but any help would be appreciated! (I am aware it is in studs)

1 answer

Use Magnitude with the subtraction (assuming store is the total distance in studs)

local total = 0
local lastPos = part.Position

while true do
	local distance = (part.Position - lastPos).Magnitude
	total = total + distance
	lastPos = part.Position
	wait()
end

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