Hi! Honestly, I want to say that I am blown away by the cool animation in the video lol! Really creative idea 
Anyways, I will point out the key issue in your code which is point out in Camera Documentation and a potential solution.
The problem
If you read the documentation I linked up there, you will notice a note that say
what this means is that
:ViewportPointToRay() unfortunatly cannot be used directly for viewportFrames. This is because the viewport size is incorrect leading to it calculating invalid ray direction.
The solution
Since roblox does not support this function in viewportFrames, we will BECOME the roblox engineers and write our own function to do something like that. I will not provide you will the entire code in the sense of the entire code(i mean that you cannot just copy and paste in one click) but I wll provide sniplets for you to to copy and paste multiple times. This is to make you hopefully read my explanation 
defining the function and paramters
Firstly, we will need to define the function (obviously). For this function, we will need parameters such as ViewportFrame, realtive mouse X and relative mouse Y
--[[
@param viewport: ViewportFrame
@param x: mouse X position relative to viewport AbsolutePosition.X (mouse - viewportPos)
@param y: mouse Y position relative to viewport AbsolutePosition.Y (mouse - viewportPos)
]]
local function ViewportPointToRay(viewport:ViewportFrame,x:number,y:number)
end
next we will get some data from the viewportFrame, that we will need later
local viewportSize = viewport.AbsoluteSize
local camera = viewport.CurrentCamera ::Camera
local fieldOfView = camera.FieldOfView
local aspectRatio = viewportSize.X/viewportSize.Y
get the normalised X and Y position
ok now these steps will get a little more mathy. We can imagine the camera as an isosceles where:
- the angle of the “sharp part” is the field of view
- the flat part is the screen
we now want the normalised X and Y position. We will normalise the positions to (-1, 1) relative to viewportSize. The reason why it is (-1, 1) and not (0, 1) like normal roblox UI scale is cuz it make sense that 0 is something right in front of you. If somethign is right in front of your eyes, you do not need to move your head up or down. Thus (0, 0) is the normalised position in this case not (.5, .5).
-- now we will get the normalised position(-1,1) of x and y
local normalisedX = ((x/viewportSize.X) * 2) - 1
local normalisedY = ((y/viewportSize.Y) * 2) - 1
next we will calculate the ray’s vector(relative to camera)
for this part, we will need the “Screen size” in the image provided on top. We can get it by doing
local opposit = math.tan(math.rad(fieldOfView)/2) * 1 --> tan = op/adj, we can assume adj is 1
next, we will get the relative direction of X and Y. Since we now have half the screen size, we can multiply half the screen size by the normalise position.
local relativeDirX = normalisedX * opposit
local relativeDirY = normalisedY * opposit
however, here comes a problem. I faced. the relativeDirX always seems to be wrong …
the issue is that the “Screen size” is only accurate for the Y axis. This is because the camera’s FOV verticle so it is actaully something more like this:
only for the verticle axis, the field of view will be accurate and the screen size will be correct. Thus, we will need to multiply relativeDirX by aspect ratio
local relativeDirX = normalisedX * aspectRatio * opposit
##reuturning a ray
ok, currently, the directions we have are relative to the camera. We can do this by using cf:VerctorToWorldSpace(vec)
local rayDir = camera.CFrame:VectorToWorldSpace(Vector3.new(relativeDirX,-relativeDirY, -1).Unit)
there is a -1 in the z axis because -1 in roblox is front. Also, the 1 value is why we can assume adj is 1 in this part.
Also, do note that Y is inverted for some reaon lol
local opposit = math.tan(math.rad(fieldOfView)/2) * 1 --> tan = op/adj, we can assume adj is 1
lastly, we will return a ray
return Ray.new(camera.CFrame.Position, rayDir)
now time to piece this function together! I hope this makes sense and please ask any questions if you have (or if your function dont work, please send me your function for me to look through)
video of the working function:
this is my test script btw 
mouse.Button1Down:Connect(function()
local viewportPosition = script.Parent.ViewportFrame.AbsolutePosition
local relativeMouseX,relativeMouseY = mouse.X-viewportPosition.X,mouse.Y-viewportPosition.Y
local ray = ViewportPointToRay(script.Parent.ViewportFrame,relativeMouseX,relativeMouseY)
game.Workspace.ViewportFrameWorldModel.Attachment.WorldPosition = ray.Origin
game.Workspace.ViewportFrameWorldModel.Attachment1.WorldPosition = ray.Origin + ray.Direction * 500
local raycast = workspace:Raycast(ray.Origin,ray.Direction * 1000, params)
print(raycast and raycast.Instance or "nil")
end)