Hi!
At first glance this might seem it should work, but there are several things going wrong.
First of all, you make a variable named Char, but it doesn’t contain anything, it is nil. When you put that into a table called Blacklist, you will end up with an empty table (because nil represents an empty spot in a table). The reference to your char variable is not conserved, and putting something in Char later does not add it to the blacklist array.
Similarly, another problem comes into view. Consider this code, and what you expect to happen. Then try it in studio:
local params = RaycastParams.new()
local filterTable = {}
params.FilterDescendantsInstances = filterTable
table.insert(filterTable, game.Workspace:WaitForChild("Baseplate"))
print(params.FilterDescendantsInstances)
It might seem logical to assume that if you put a new item into the Blacklist array after setting the Blacklist as the FilterDescendantsInstances, it becomes blacklisted, but in fact roblox seems to make a copy of the provided table, instead of taking the reference. This kind of makes sense, in fact: It only uses the items in your Blacklist array that are there at the moment of setting it as the FilterDescendantsInstances.
So adding everything to Blacklist first, then setting it as FilterDescendantsInstances, should fix your problem.
Now, for some other notes to help you improve your code: As the name implies, you only need to set the character model itself, and all its descendants (it’s children, the children of children, etc) are ignored. The reason this didn’t work before is as explained, the Char variable is still empty when you add it to Blacklist and the Blacklist stays empty.
Another thing is the idiom you are using:
for i=1, #char:GetDescendants() do
table.insert(Blacklist, Char:GetDescendants()[i]
end
The normal way to do this (as explained in this case you can skip this whole loop, as blacklisting the character model also blacklists all its descendants), is as follows:
for i, item in ipairs(Char:GetDescendants() do
table.insert(Blacklist, item)
end
We could also have used pairs instead of ipairs, the difference is that pairs does not neccesarily conserve order while ipairs only works on arrays (and not on any key-value pairs, for example when the keys are strings - in that case the order is technically unknown).
The reason this is better is because first of all it is a bit faster, as the CPU doesn’t first have to count the items before starting the loop. But another issue is that potentially Char:GetDescendants() might return a different ordered array in the second call. While the array, once made, conserves its order, the second new array is not guarantueed to have the same order (probably it does, but who knows).
You could have first put the array in a variable, and use that variable twice instead of calling getDescendants twice (it is also unneccesary work to create the same list twice). But I would recommend using a loop using pairs() or ipairs() - instead of iterating over your number up to the amount of items you counted in your table, and then indexing your table with that number. It also reads much nicer!
Good luck! Let me know if I should explain any part better, and I will give it a try. I’m pretty sure you are really close to getting your weapon to work, most of the code looks great!