Cast ray to players cursor in 3d

M1.OnServerEvent:Connect(function(player,walkspeed,mousetable)
	local Camera = workspace.CurrentCamera
	local head = player.Character.Head
	local humanoid = player.Character.Humanoid
	local Damage = player.PvPStats.Damage.Value
	local blockedDamage = 0.80 * Damage
	local HumanoidRootPart = humanoid.Parent:WaitForChild("HumanoidRootPart")
	local hitbox = player.Character.HitBox

	local ray = Camera:ViewportPointToRay(mousetable[1],mousetable[2])
	local rayparams = RaycastParams.new()
	rayparams.FilterDescendantsInstances = {player.Character} 
	rayparams.FilterType = Enum.RaycastFilterType.Blacklist
	
	local raycastresult = workspace:Raycast(head.Position,ray.Direction * 10,rayparams)
	
	local commands = {
		blocking = player.Character:WaitForChild("Blocking")
	}
	
	humanoid.WalkSpeed = 9
	for i,v in pairs(commands) do
		v.Disabled = true
	end
	
	if raycastresult then
		print(raycastresult.Instance)
		local part = Instance.new("Part")
		part.Position = raycastresult.Position
		part.Anchored = true
		part.Size = Vector3.new(2,2,2)
		part.Parent = workspace
		wait(1)
		part:Destroy()
	end
	
	wait(0.3)
	
	humanoid.WalkSpeed = walkspeed
	for i,v in pairs(commands) do
		v.Disabled = false
	end
end)
local function hit (player)
	local walkspeed = player.Character.Humanoid.WalkSpeed
	local mouseposition = UserInputService:GetMouseLocation()
	local mousetable = {
		mouseposition.X,
		mouseposition.Y,
	}
	
	M1:FireServer(walkspeed,mousetable)
end

im making a combat script and i want to fire a ray at the players cursor how would i do that
(if i dont respond im prob at school)

Just use Raycast, and cast a ray from the HumanoidRootPart to the Mouse.Hit.Position.
Like this:

local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {player.Character}
Params.FilterType = Enum.RaycastFilterType.Blacklist

local Raycast = workspace:Raycast(HumanoidRootPart.Position, Mouse.Hit.Position - HumanoidRootPart.Position, Params)

Since I had trouble with rays and visualizing where they go I made a modified version of some code I found and used it to help view the ray.

function displayRay(start :Vector3, stop :Vector3, distance :number|nil) --https://devforum.roblox.com/t/how-do-you-visualize-a-raycast-as-a-part/657972/5
    local distance = distance or (start-stop).Magnitude
    local p = Instance.new("Part")
    p.Anchored = true
    p.CanCollide = false
    p.Color = Color3.new(math.random(),math.random(),math.random())
    p.Size = Vector3.new(0.1, 0.1, distance)
    p.CFrame = CFrame.lookAt(start, stop)*CFrame.new(0, 0, -distance/2)
    p.Parent = workspace
    delay(5,function()
        p:Destroy()
    end)
end