Ray won't register hits

Hi, I’m trying to make a freeze ray but somehow the ray won’t hit.


Error:

Here is my script

local Tween = game:GetService("TweenService")
local onCoolDown = false
script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr, mousePos)
	if onCoolDown == false then
		script.Parent.Handle.Fire:Play()
		onCoolDown = true
		local trajectory = Instance.new("Part")
		local rayCastParams = RaycastParams.new()
		rayCastParams.FilterDescendantsInstances = {plr.Character, script.Parent.Handle, trajectory, workspace.Baseplate}
		rayCastParams.FilterType = Enum.RaycastFilterType.Blacklist

		local result = workspace:Raycast(script.Parent.Handle.Position, (mousePos - plr.Character.HumanoidRootPart.Position)*math.huge,rayCastParams)
		local distance = (script.Parent.Handle.Position - mousePos).magnitude
		
		trajectory.Parent = workspace
		trajectory.Name	= "Tragectory"
		trajectory.Transparency = 0
		trajectory.Anchored = true
		trajectory.CanCollide = false
		trajectory.Locked = true
		trajectory.BrickColor = BrickColor.new("Cyan")
		trajectory.Material = Enum.Material.Neon
		trajectory.Size = Vector3.new(.1,.1,distance)
		for i = 0, distance, 6 do
			trajectory.CFrame = CFrame.new(script.Parent.Handle.CFrame.p, mousePos)*CFrame.new(0,0,-distance / 2)
		end
		--[[
		spawn(function()
			Tween:Create(trajectory, TweenInfo.new(.5, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0, false, 0),{Transparency = 1}):Play()
			wait(1)
			trajectory:Destroy()
		end)
		--]]
		spawn(function()
			print(result.Instance.Name)
		end)
		
		if result then
			local hitPart = result.Instance
			local model = hitPart:FindFirstAncestorOfClass("Model")
			print(result.Instance.Name)
			print(result.Instance.Parent)
			if model and model:FindFirstChild("Humanoid") and model ~= plr.Character then
				print(model)
				local Humanoid = model.Humanoid
				Humanoid.WalkSpeed = 0
				local Freeze = Instance.new("Part", workspace)
				Freeze.CFrame = model.HumanoidRootPart.CFrame
				Freeze.Material = Enum.Material.Ice
				Freeze.Anchored = true
				Freeze.CanCollide = true
				Freeze.BrickColor = BrickColor.new("Cyan")
				Freeze.Transparency = 0.5
				Freeze.Size = Vector3.new(4.5, 5.5, 4)
				Freeze.Parent = workspace
				model.HumanoidRootPart.Anchored = true
			end
			
		end
		script.Parent.Handle.Reload:Play()
		wait(1.4)
		onCoolDown = false
	end
	
end)

The spawn around line 35 is useless, and you should check if result exists before trying to print its properties… like on line 38.

yes i know that but when i shoot at the dummy the result is nil so the hit wasn’t register

I can’t test at the moment to be certain, but try changing the direction argument to use the Handle instead of the HumanoidRootPart - you might have the wrong angle.