It sounds like you’re trying to achieve a selective raycasting behavior that is not currently possible with the existing RaycastParams options. However, there are a few workarounds you can try to achieve the desired effect.
One possible solution is to perform multiple raycasts with different filters and combine their results. For example, you could perform one raycast with the whitelist and another with the blacklist, and then only consider hits that are present in the whitelist but not in the blacklist.
Here’s an example implementation:
local Characters = {}
for _, Player in pairs(game.Players:GetPlayers()) do
if Player.Character then
table.insert(Characters, Player.Character)
end
end
local Whitelist = Characters
local Blacklist = {game.Players.LocalPlayer.Character}
local WhitelistHits = workspace:Raycast(game:GetService("UserInputService").MouseBehavior.Position, workspace.CurrentCamera.CFrame.LookVector * 100, RaycastParams.new().FilterDescendantsInstances = Whitelist)
local BlacklistHits = workspace:Raycast(game:GetService("UserInputService").MouseBehavior.Position, workspace.CurrentCamera.CFrame.LookVector * 100, RaycastParams.new().FilterDescendantsInstances = Blacklist)
local Hits = {}
if WhitelistHits then
for _, Hit in pairs(WhitelistHits) do
if not table.find(BlacklistHits, Hit) then
table.insert(Hits, Hit)
end
end
end
-- Process the hits as needed
This code performs two separate raycasts, one with the whitelist and one with the blacklist, and then combines their results into a new table of hits that are present in the whitelist but not in the blacklist.
Another possible solution is to use a custom filtering function instead of the RaycastParams options. This would allow you to implement any kind of filtering logic you need, including both whitelist and blacklist behavior.
Here’s an example implementation:
local Characters = {}
for _, Player in pairs(game.Players:GetPlayers()) do
if Player.Character then
table.insert(Characters, Player.Character)
end
end
local Whitelist = Characters
local Blacklist = {game.Players.LocalPlayer.Character}
local function CustomFilterFunction(Part)
if table.find(Whitelist, Part) then
return true
end
if table.find(Blacklist, Part) then
return false
end
-- Add any other filtering logic as needed
return true
end
local Hit = workspace:FindPartOnRayWithIgnoreList(Ray.new(game:GetService("UserInputService").MouseBehavior.Position, workspace.CurrentCamera.CFrame.LookVector * 100), Blacklist, false, true, CustomFilterFunction)
-- Process the hit as needed
This code uses the FindPartOnRayWithIgnoreList function instead of the Raycast function, and passes a custom filtering function as the last argument. This function checks if the part is in the whitelist or the blacklist, and returns true or false accordingly. You can add any other filtering logic you need to this function as well.
I hope these suggestions help you achieve the raycasting behavior you need.