Help me with raycast bug

Basically for whatever reason, I can’t headshot players but can headshot enemies with raycast. Anyone know why? Body shots work though.

1 Like

Did you blacklist all of the accessory hitboxes?

Yes i did already did that, i also blacklisted the player’s hitbox.

1 Like

Can you share the raycast script please

local module = {}

local CS = game:GetService(“CollectionService”)

local DMGMOD = require(script.Parent:WaitForChild(“DamageModule”))

local deb = game:GetService(“Debris”)

local remote = game.ReplicatedStorage.Remotes:WaitForChild(“GunShot”)

local VFX = game.ReplicatedStorage.Remotes:WaitForChild(“VFX”)

local range = 100

local KFX = require(game.ServerScriptService:WaitForChild(“Modules”):WaitForChild(“KillEffects”))

function CheckKFX(Check, KillEffect, enemy, headshot, player)

if Check then 
	print(KillEffect.Value)
	if not KFX[KillEffect.Value] then
		if headshot==true then
			
			KFX["Headshot"](enemy, player)
			
		end
	elseif KFX[KillEffect.Value] then
		KFX[KillEffect.Value](enemy, player)
	end
	
end

end

function Fired(player, mouse, startpoint)

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

local Tool = character:FindFirstChildOfClass("Tool")


local Direction = (mouse.Position - startpoint).Unit * range

if Tool:FindFirstChild("BulletCount") then
	if Tool:FindFirstChild("BulletCount").Value==0  or Tool:FindFirstChild("BulletCount").Value<0 then return end
	Tool:FindFirstChild("BulletCount").Value-=1
	
	local Config = Tool:FindFirstChild("Config") 
	
	if not Config then return end
	
	VFX:FireAllClients( "BulletSound", character, Config.ShootSFX.Value)
	VFX:FireAllClients("SmallShine", startpoint)

	local Params = RaycastParams.new()
	
	local BlockedAccessories = {}
	for _, v in pairs(workspace:GetDescendants()) do
	
		if v:IsA("Accessory") then
			table.insert(BlockedAccessories, v)
		end
		end
	Params.FilterType = Enum.RaycastFilterType.Exclude
	Params.FilterDescendantsInstances =  {character, BlockedAccessories}
	
	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)
				
				return
					
			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)

				
				
				return
				end

	
		end
		
	elseif not Raycast then

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

end
end

end
remote.OnServerEvent:Connect(Fired)

return module

pretty much only look at the “Fired” function part, and i kinda don’t know how dev forum formats code so yea.

When Raycasting, you should only blacklist yourself to avoid hitting yourself intead of all accesories in the area. FilterDescendantsInstances will already do that for you when placing the character in the array, so there is no need to ad everything. In the case you need to add something else, use RaycastParams:AddToFilter()

Params.FilterDescendantsInstances =  {character}
-- all accessories will be blacklisted regardless
-- thats why its called "Filter Descendants Instances"
  1. You can either add 4 spaces onto any sentence or line.
  2. use 3 backticks ``` to format

He has to blacklist the other accessories in the workspace too

for the workspace blacklist, i did it to test if accessories were the problem, so i put a bacon hair dude which the headshot worked which is weird. ima look back at it again tho.

Tried it, doesn’t work, same outcome. Maybe ill look at other posts to see if anyone has had the same problem.