Enemies' accessories blocking raycasts in SimpleCast module

local filterTable = {Character}
local castParams = RaycastParams.new()
castParams.FilterType = Enum.RaycastFilterType.Exclude
castParams.FilterDescendantsInstances = filterTable

local Settings = {
	MaxLifeTime = 10,
	CacheSize = 10,
	CacheGrowthSize = 0,
	Gravity = Vector3.new(0, -15, 0),
	RaycastParam = castParams,
	OnCastHit = function(self, hitObj, castData, newPosition)
		if hitObj.Instance and hitObj.Instance.Parent then
			if hitObj.Instance.Parent:IsA("Accesory") then
				table.insert(filterTable, hitObj.Instance)
				castParams.FilterDescendantsInstances = filterTable
				return
			else
				local hum = hitObj.Instance.Parent:FindFirstChild("Humanoid")
				if hum then
					local distance = (FirePoint.WorldPosition - newPosition).Magnitude
					FireEvent:FireServer(hum, hitObj.Instance.Name, distance)
				end
			end
		end
		self:CastTerminate(castData)
	end,
}

Hitting the player and everything else works, but accessories are still blocking shots. Please help ! :sob:

I think the most efficient way to combat this would just be to set CanQuery to all of the accessories when the player’s character is added. When you set CanQuery to false, it excluces it from spatial query operations (raycasting in your case):

-- Server script in ServerScriptService
game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAppearanceLoaded:Connect(function(char)
		for _,v in ipairs(char:GetChildren()) do
			if (v:IsA("Accessory")) then
				v.Handle.CanQuery = false
			end
		end
	end)
end)

I’ve tried this, and the accessories still block.

EDIT: I’m dumb, it works. :man_facepalming: I’ve been testing it on rigs that i had replaced in workspace

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