Is my first try at creating a realistic RayCast Bullet efficient?

Before I implement stuff like wall-penetration, trajectory calculation and wall deflection, I would like to have some feedback. Thank you in advance:)

function Bullet.new(OriginCF,lookVector,Caliber)
	--Basepart to mak the curve visible
	--local Bullet_Base = Instance.new("Part")
	--Bullet_Base.Size = Vector3.new(3,3,3)
	--Bullet_Base.CanCollide = false
	--Bullet_Base.Anchored = true
	--Bullet_Base.Parent = game.Workspace.Filter
	--These will affect the bullet trajectory
	local Mass = script:FindFirstChild(Caliber).Mass.Value
	local Range = script:FindFirstChild(Caliber).Range.Value
	local Velocity = script:FindFirstChild(Caliber).Velocity.Value

	local CurCFrame = OriginCF
	local Direction = nil 
	local TravelledDistance = 0
	local RayParams = RaycastParams.new()
	RayParams.FilterType = Enum.RaycastFilterType.Blacklist
	RayParams.FilterDescendantsInstances = game.Workspace.Filter:GetChildren()--Justa folder that contains the blacklistet baseparts

	local RayLength = 10
	local delta, lastTick, startTime = 0, tick(), tick()
	local TotalDistance = 0
	local LastRayEnd = CurCFrame
	local DistanceSinceLastRay = 0
	local function loop() 
		while  TotalDistance < Range do
			RS.Heartbeat:Wait()
			delta = tick()-lastTick
			RayParams.FilterDescendantsInstances = game.Workspace.Filter:GetChildren()
			local TravelDistance = delta*Velocity
			TotalDistance = TotalDistance+TravelDistance
			
			local DropAmount = 0--this is where the physics calculation will take place
			Velocity = Velocity
			
			Direction = (CurCFrame+lookVector*TravelDistance)-Vector3.new(0,DropAmount,0)
			--Bullet_Base.Position = Direction.Position

			if DistanceSinceLastRay >= RayLength then
				local Result = game.Workspace:Raycast(LastRayEnd.Position,Direction.Position-LastRayEnd.Position,RayParams)
				if Result then
					if Result.Instance.Parent:FindFirstChild("Humanoid") then
						Result.Instance.Parent:FindFirstChild("Humanoid").Health = 0
					end
				end

				--making the rays visible for testing purposes
				
				--local distance = (LastRayEnd.Position - Direction.Position).Magnitude
				--local p = Instance.new("Part",game.Workspace.Filter)
				--p.Anchored = true
				--p.CanCollide = false
				--p.Size = Vector3.new(0.1, 0.1, distance)
				--p.CFrame = CFrame.lookAt(LastRayEnd.Position,Direction.Position)*CFrame.new(0, 0, -distance/2)

				LastRayEnd = Direction 

				DistanceSinceLastRay = 0
			else
				DistanceSinceLastRay = DistanceSinceLastRay+TravelDistance
			end
			CurCFrame = Direction
			lastTick = tick()
			RayParams.FilterDescendantsInstances = game.Workspace.Filter:GetChildren()

		end
	end
	coroutine.wrap(loop)()
end
return Bullet