I’ve heard of raycast blacklisting but not raycast whitelisting. I’m hoping it’s a thing because it’s only about 5 out of about 1000 parts that I want the raycast to look at. I can’t imagine blacklisting 1000 parts, it’s just impractical. Does anyone know how I can achieve whitelisting just the parts in a model?
Try this:
It like they’ve put the parts the ray is allowed to hit into a folder and checked the folder contents, not the entire place.
Is this it:
-- Build a "RaycastParams" object and cast the ray
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {caster.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
Raycast parameters?
Yes, you should use Raycast parameters, in raycast “FilterDecendantsInstances” you need to put in the array Model:GetChildren()
and in FilterType it needs to be Whilelist, so only the childrens inside the model would be affected by the ray
I might be wrong here, but since it’s called “FilterDecendantsInstances” does that mean it automatically selects all the descendants? Because in the docs example it just says {caster.Parent}
.
Maybe you could test it, but i think that the “Decendants” are from the hitted parts in the ray, not the thing inside the array, try it or do my method of ModelGetChildren()
Whitelisting is the same as blacklisting, you just need to change the ‘FilterType’ property of the ‘RaycastParams’ object from Enum.RaycastFilterType.Blacklist
to Enum.RaycastFilter.Whitelist
.
https://developer.roblox.com/en-us/api-reference/enum/RaycastFilterType
I’ve tested both of them out and both ways seem to work the exact same.
Edit: I printed {script.Parent} -- the model
and {script.Parent:GetChildren() -- models parts
and here are the results:
The first one is script.Parent
, the second is the one with :GetChildren()
So it seems if you select a model, it will not add the children to the table but rather make the whole model whitelisted/blacklisted anyway.