I am currently making a gun script that uses raycasting. To make sure it does not instantly damage the player, I am making a artificial bullet time script. This requires me getting the distance from the ray origin to the point where the ray hit something, I am currently trying this code in order to make sure the ray damages the player even if the bullet "misses" the player. This is what I have so far:
local character = script.Parent.Parent
local player = game.Players:GetPlayerFromCharacter(character)
local mouse = player:GetMouse()
local ray = Ray.new(muzzle.CFrame.p, (mouse.Hit.p - muzzle.CFrame.p).unit * range)
local rayDistance = ray:Distance()
local shotTime = rayDistance / velocity
local part1 = game.Workspace:FindPartOnRay(ray, character, false, true)
wait(shotTime)
local ray2 = Ray.new(muzzle.CFrame.p, (mouse.Hit.p - muzzle.CFrame.p).unit * range)
local part2 = game.Workspace:FindPartOnRay(ray2, character, false, true)
if part1 == part2 then
print("PIE")
end
I get this error though:
Workspace.M4 Carbine.BulletCreator:14: bad argument #1 to 'Distance' (Vector3 expected, got Ray)
Am I doing the wrong function in order to get what I desired, or am I doing the function?

2 comments
I took a look at the WIKI; apparently, you need to give it a Vector3 value (thus why your error says that).
To add onto what I said: it's, from what I got from looking at its example, set up to retrieve the distance from Point A to Point B, and from there you can check if the distance is at a certain point.