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")

	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 *,2),math.random(-2,2),math.random(-2,2))
		local RaySpread =,y,z) *,2),math.random(-2,2),math.random(-2,2))
		game.ReplicatedStorage.Remotes.Projectile:FireServer("AirShotgun", Spread)

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

I thought that Workspace:FindPartOnRay was depricated

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

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