Hello! I have a question on how I can add Instances to my Raycast FilterDescendantsInstances array.
I have a gun system using the workspace:Raycast() method in where i’m trying to ignore nearly
transparent/transparent parts. To acheive ignoring transparent parts, I’m having it continiously try a raycast and add transparent parts to the ignore list until the raycast instance is not transparent.
However the issue I am having is I can’t seem to add any new instances to the FilterDescendantsIntances array. I’ve tried testing it by doing:
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {character, workspace.IgnoreList}
print(raycastParams["FilterDescendantsInstances"])
table.insert(raycastParams["FilterDescendantsInstances"], workspace.Materials)
print(raycastParams["FilterDescendantsInstances"])
However both those prints printed the same exact same thing and workspace.Materials
did not get added into the array.
Does anyone have any ideas on how I can acheive this? Thank you!
1 Like
Does character or workspace.Ignorelist appear?
If you add workspace.Materials directly to the intial table, like {character, workspace.IgnoreList, workspace.Materials} does that work?
1 Like
Yes, character and workspace.Ignorelist do appear.
As for the workspace.Materials, it was just test if it would add in the array. Realistically, I would want to be adding transparent part in the array during the game and not preset.
You would call the Raycast paramaters at the time of casting your rays instead of trying to create the raycast paramaters and hold onto them. Instead you could make a table that has your list inside of it, add and remove from that table then when you go to raycast you refer the paramaters filter to that table
1 Like
Yeah, I tried that but I can’t store a table of instances inside FilterDescendantsInstances, if that’s what you meant. Is there any other way you know how to do it?
local part = game.workspace.part
local storedBlackList = {}
table.insert(storedBlackList, part)
local function RayNow() --Some function that tells your system to raycast
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = storedBlacklist
end
wait(5)
RayNow()
table.remove(storedBlacklist, 1)
wait(3)
RayNow()
So this is just a quick example, but basically if I want to run a raycast with specific black list i’ve got stored then one way we can do that is by having a table, above called storedBlacklist in which we add the part into the list, do a ray, then remove, and run a ray again.
Now this doesn’t actually run a ray, but you can use bindable or remote functions or module scripts to add or remove into the table, so that when you go to run a raycast function it takes the table you’re trying to reference.
Do you have a source code that you’re working with that’s not working?
4 Likes
Oh that snippet cleared it up for me, I forgot I could make the array a seperate variable. Thank you! I should know what to do now.
1 Like