Any idea why raycasting isn't working here?

I’m trying to make a shotgun that uses rays to check for characters but the rays aren’t actually touching the characters I’m trying to shoot at. I already tried using visuals to try to understand where the rays were going but the parts were going to the positions intended. The rays aren’t touching the characters and fail to register the remote event for damage.

-- local script
local TweenService = game:GetService("TweenService")

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Tool = script.Parent
local Nozzle = Tool:WaitForChild("Handle"):WaitForChild("Nozzle")

Tool.Activated:Connect(function()
	for i=1,10 do
		local HRP = Player.Character.HumanoidRootPart
		local MousePos = Mouse.Hit
		local x,y,z = MousePos.X, MousePos.Y, MousePos.Z
		local Spread = MousePos * CFrame.new(math.random(-2,2),math.random(-2,2),math.random(-2,2))
		local RaySpread = Vector3.new(x,y,z) * Vector3.new(math.random(-2,2),math.random(-2,2),math.random(-2,2))
		game.ReplicatedStorage.Remotes.Projectile:FireServer("AirShotgun", Spread)



		local RayP = RaycastParams.new()
		RayP.FilterType = Enum.RaycastFilterType.Blacklist
		RayP.FilterDescendantsInstances = {Tool}
		
		local RayR = workspace:Raycast(Nozzle.Position, RaySpread, RayP)
		if RayR then
			print(RayR.Instance)
			local hit = RayR.Instance
			local hitHumanoid = hit.Parent:FindFirstChild("Humanoid")
			print(hitHumanoid)
			if hitHumanoid then
				if game.Players:GetPlayerFromCharacter(hit.Parent) ~= Player then
					game.ReplicatedStorage.Remotes.Damage:FireServer(hitHumanoid, 5)
				end
			end
		end
	end
end)
-- Server script
game.ReplicatedStorage.Remotes.Damage.OnServerEvent:Connect(function(player, Target, Damage)
	Target:TakeDamage(Damage)
end)

I thought that Workspace:FindPartOnRay was depricated

Could have been, even so sometimes the depreciated options still work.
I will have to check this

Edit:
Yes it has indeed been depreciated. I will remove my previous post as to not confuse things.
Here is the intro for it

Thank you, do you have any idea how I went wrong though?

I’m not sure. I was way too comfortable with the old method ill edit this is I see anything.

Have you tried using prints to track what is going on?
You would want prints for:
Ray creation, Object hit, If humanoid was found,

1 Like

I found the problem, thank you, I was using a position instead of unit