-
**What do you want to achieve?
I want to be able to raycast without having the player’s accessories blocking the ray. -
What is the issue?
Although I have excluded the accessories and handle, they are still blocking my ray? I am unsure if it’s because of the raycast filtering param not accepting accessories as hats. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have made a code that put these accessories and handles into an array. There are other approaches to this, but I specifically want my code to be used in this case.
The following code is in localscript
local MAX_DISTANCE = 1000 local excludeTable = {} -- Filter all mouse related parts for _, filterInstance in pairs(game.Workspace.FilterMouse:GetChildren()) do table.insert(excludeTable, filterInstance) end for _, part in pairs(character:GetChildren()) do if part.ClassName == "Accessory" then for _, descedant in pairs(part:GetDescendants()) do if descedant:IsA("BasePart") then table.insert(excludeTable, descedant) end end end end local newRaycastParams = RaycastParams.new() newRaycastParams.FilterDescendantsInstances = excludeTable newRaycastParams.FilterType = Enum.RaycastFilterType.Blacklist local newRayDirection = (mouse.Hit.Position - character.Head.Position).Unit * MAX_DISTANCE local newRaycastResult = game.Workspace:Raycast(character.Head.Position, newRayDirection, newRaycastParams) -- Go through all parents until character is found if newRaycastResult then local part = newRaycastResult.Instance while part.Parent ~= nil do print(part.Name) if part:FindFirstChildWhichIsA("Humanoid") then print("found character") local otherCharacter = part for _, children in pairs(character:GetChildren()) do if children.ClassName == "Accessory" then for _, descedant in pairs(children:GetDescendants()) do if descedant:IsA("BasePart") then table.insert(excludeTable, descedant) end end end end break end print("didn't found character") part = part.Parent end end print(excludeTable) -- shows all parts excluded -- refire raycast with new excluded parts local raycastParams = RaycastParams.new() raycastParams.FilterDescendantsInstances = excludeTable raycastParams.FilterType = Enum.RaycastFilterType.Blacklist local rayDirection = (mouse.Hit.Position - character.Head.Position).Unit * MAX_DISTANCE local raycastResult = game.Workspace:Raycast(character.Head.Position, rayDirection, raycastParams) if raycastResult then print(raycastResult.Instance) -- Prints handle that was already excluded?? print(raycastResult.Instance.Parent) end