Raycast Being Inconsistent

Hello!

I made a simple gun system. For some reason, when my cursor is on the player’s head, it doesn’t register the hit (the raycast doesn’t even come in contact with the head, as if it ignored it)

Here is a clip:

Server script:

re.OnServerEvent:Connect(function(plrWhoShot, mPos, orig)
	currentAmmo.Value = currentAmmo.Value - 1
	
	local origin = orig
	local direction = (mPos - origin).Unit * 10000
	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {handle, plrWhoShot.Character}
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	
	
	
	if currentAmmo.Value > 0 then
	local raycastResult = workspace:Raycast(origin, direction, raycastParams)
	local sound = script.Parent:FindFirstChild("Handle").ak47
	sound:Play()
	local dmg = 26 --to CHANGE
		if raycastResult then
			if raycastResult.Instance.Parent:FindFirstChild("Humanoid") or raycastResult.Instance:FindFirstAncestorWhichIsA("Model"):FindFirstChild("Humanoid") then
				local rs = game:GetService("ReplicatedStorage")
				local reSend = rs.sendHitPart
				
				reSend:FireClient(plrWhoShot, raycastResult.Instance.Name)
				
				print(raycastResult.Instance.Name)
				local hum = raycastResult.Instance.Parent:FindFirstChild("Humanoid")
				if hum.Parent:FindFirstChild("Armorlvl1Part") then
					hum:TakeDamage(26*0.975) --TO CHANGE
				elseif hum.Parent:FindFirstChild("Armorlvl2Part") then
					hum:TakeDamage(26*0.90) --TO CHANGE
				elseif hum.Parent:FindFirstChild("Armorlvl3Part") then
					hum:TakeDamage(26*0.82) -- TO CHANGE
				elseif hum.Parent:FindFirstChild("Armorlvl1Part") == nil and hum.Parent:FindFirstChild("Armorlvl2Part") == nil and hum.Parent:FindFirstChild("Armorlvl3Part") == nil then
					hum:TakeDamage(26)
				end
				if hum.Health <= 0 then
					plrWhoShot.ValueFolder.Kills.Value = plrWhoShot.ValueFolder.Kills.Value + 1
					plrWhoShot.ValueFolder.XP.Value = plrWhoShot.ValueFolder.XP.Value + 100
					print(plrWhoShot.ValueFolder.Kills.Value, plrWhoShot.ValueFolder.XP.Value)
				end
      		end
		end
	end
end)

Any reasons this is happening?
Thanks a lot!

It’s because the ray is hitting the handle that’s inside of the player’s hair accessory

1 Like

Isn’t the Handle of that accessory a descendant of the Player’s model?

Isn’t it supposed to still do damage because of this line of code:

if raycastResult.Instance.Parent:FindFirstChild("Humanoid") or raycastResult.Instance:FindFirstAncestorWhichIsA("Model"):FindFirstChild("Humanoid") then

Ooops, just realised the mistake, I forgot to blacklist Parts and there was an invisible part right where the player was.

Sorry.