Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My distance traveled script is inaccurate, why?

Asked by 2 years ago
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

Log in to vote
0
Answered by
Miniller 562 Moderation Voter
2 years ago

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
Ad

Answer this question