Custom mouse raycast issue

Hello developers, I would like to know what is causing my raycast to break.
I’ve tried to replace the old raycast with a custom one but for whatever reason it just stays where it started initially upon joining.

local userInputService = game:GetService("UserInputService")

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local runService = game:GetService("RunService")

local mousePos = userInputService:GetMouseLocation()

local mouseRay = workspace.CurrentCamera:ViewportPointToRay(mousePos.X, mousePos.Y)
mouseRay = workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 1000)

	if mouseRay then
		print("Object/terrain hit:", mouseRay.Instance:GetFullName())
		print("Hit position:", mouseRay.Position)
		print("Surface normal at the point of intersection:", mouseRay.Normal)
		print("Material hit:", mouseRay.Material.Name)
		print("Nothing was hit!")

Any help with this is appreciated,
Thanks, MBroNetwork.

I’ve fixed it, turns out I was being stupid and should’ve just used “Mouse.UnitRay” instead of the camera and UIS mouse position.

You were only creating and casting the ray once (when the script first executes). The “.RenderStepped” event was just printing the results of that raycast every frame.

I figured it out after I made the post that I was being an idiot and didn’t call the ray more than once and also used workspace.CurrentCamera:ViewportPointToRay instead of Mouse.UnitRay