Help with Headshot Raycast bug (Again)

Im posting this again because I haven’t found a solution. Basically I can headshot npcs but not players. Although body shots work on players. Anyone know why or have an idea?

function Fired(player, mouse, startpoint)

	local character = player.Character or player.CharacterAdded:Wait()
	local HRP = character:WaitForChild("HumanoidRootPart")

	local Tool = character:FindFirstChildOfClass("Tool")

	if Tool:FindFirstChild("BulletCount") then
		if Tool:FindFirstChild("BulletCount").Value==0  or Tool:FindFirstChild("BulletCount").Value<0 then return end

		local Config = Tool:FindFirstChild("Config") 

		if not Config then return end

		VFX:FireAllClients( "BulletSound", character, Config.ShootSFX.Value)
		VFX:FireAllClients("SmallShine", startpoint)

		local Params =

		local BlockedAccessories = {}
		for _, v in pairs(workspace:GetDescendants()) do

			if v:IsA("Accessory") then
				table.insert(BlockedAccessories, v)

		Params.FilterType = Enum.RaycastFilterType.Exclude
		Params.FilterDescendantsInstances =  character:GetDescendants()

		local Direction = (mouse.Position - startpoint).Unit * range
		local Raycast = workspace:Raycast(startpoint, Direction, Params)

		if Raycast then

			local hit = Raycast.Instance
			local EndPos = Raycast.Position

			VFX:FireAllClients("BulletParticle", startpoint, Config.BulletColor, EndPos,true)

			if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name~=player.Name then
				local Hum = hit.Parent:FindFirstChild("Humanoid") 
				if Hum.Health<1 then return end
				if hit.Name=="Head" then

					local Check = DMGMOD.DamageEnemy(player, hit.Parent, Hum, 100)

					local KillEffect = Config:FindFirstChild("KillEffect")

					CheckKFX(Check, KillEffect.Value, hit.Parent, true, player)


				elseif hit.Name~="Head" then

					local Check = DMGMOD.DamageEnemy(player, hit.Parent, Hum, 25)

					local KillEffect = Config:FindFirstChild("KillEffect")

					CheckKFX(Check, KillEffect.Value, hit.Parent, false, player)



		elseif not Raycast then

			VFX:FireAllClients("BulletParticle", startpoint, Config.BulletColor, Direction, false)
			print("Not Hit")



Try a different approach on blacklisting the players character

Params.FilterDescendantsInstances =  {player.Character}

tried it. Didn’t work. Idk or have any idea on this, seen other scripts with ray cast and they can detect player heads.

Most likely it detects hat hitbox that blocks the head hitbox. Other scripts are most likely aware of that. You have to exclude hat hitboxes from raycasting somehow. The quickiest (but not the best) way would be putting a server script in the StarterCharacterScripts

for i, instance in script.Parent:GetChildren() do
	if instance:IsA('Accessory') then
		for i, accInstance in instance:GetDescendants() do
			if accInstance:IsA('BasePart') then accInstance.CanQuery = false accInstance.CanTouch = false end

This script basically sets CanQuery to false of all parts associated with hats. Try this

i’ve tried blacklisting accessories, and making CanQuery false, for some reason it just phases through the players head. Here’s it without hats.

nvm i found the solution. For whatever reason, position only replicated on client side so i used CFrame instead and it worked.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.