Problems with Ray

It’s like a postscript to the previous “Grenade Launcher” article, but I found that it could be solved by turning from the previous position(this is the “lastposition” in lua) to the current position and flying Ray, but sometimes it does not touch the ground. It may disappear in.
Script of it:

local direction = script.Parent.Position - lastposition
local ray = Ray.new(lastposition, direction * 1)

If Ray.Origin is set to the previous position and Ray.Direction is set to the current position, explosions will occur randomly around it.
Script of it:

local ray = Ray.new(lastposition, script.Parent.Position)

How can I do it exactly?
Thank you.