From what I understand, what you’re doing here is updating the CFrame every __ which does the same job as moving it with something like a vectorForce. Technically, this isn’t velocity and is just a part which you’re constantly updating. This means there’s no function to calculate its velocity.
You could, however, to make it a simpler process for you, turn your solution into a function which you can then call at your leisure.
If you are moving a part via CFrame then you should probably already have the formula for the velocity like so:
local RunService = game:GetService("RunService")
local RATE_PER_SECOND = 2
local part = Instance.new("Part")
part .Anchored = true
part .Parent = workspace
RunService.Heartbeat:Connect(function(step)
local increment = RATE_PER_SECOND * step
part*= CFrame.new(0,increment,0) -- move the part up 2 studs per second
--velocity is (0,Rate_Per_Second,0)
end)
Otherwise if it’s more complicated you can just measure the rate of change of displacement which is velocity
local RunService = game:GetService("RunService")
local RATE_PER_SECOND = 2
local part = Instance.new("Part")
part .Anchored = true
part .Parent = workspace
local previousPartPosition = part.Position
RunService.Heartbeat:Connect(function(dt)
local displacement = part.Position - previousPartPosition
local velocity = displacement/dt -- your part velocity
previousPartPosition = part.Position
end)
Thanks for taking the time to type this solution! Hopefully, there will be a built-in solution for this in the future. In the meantime, I’ll do this and make it into a function like what Benified4Life said.