Sorry if the question is not clear. But I’m making a building system like in Minecraft (to kill time). I used raycasting to place the blocks. However, the raycast parameters are not working properly. Here is my script (only the important part):
-- Local Script stored in a tool
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.FilterType.Blacklist
raycastParams.FilterDescendantInstances = game.Players.LocalPlayer.Character:GetDescendants()
raycastParams.FilterDescendantInstances[#raycastParams.FilterDescendantInstances + 1] = script.Parent.Handle
raycastParams.FilterDescendantInstances[#raycastParams.FilterDescendantInstances + 1] = game.Workspace.Parts:GetChildren() -- this line doesn't work but the code still continues
I’ve tried iterating through the “Parts” folder and adding each part to the “raycastParams.FilterDescendantInstances” table but it still doesn’t work. I’ve also tried printing out all the parts’ names stored in that table (and as you expected, maybe, the name of the parts stored in the “Parts” folder isn’t outputted ). Do you have any solutions :)?
It’s been a while since I’ve studied up on the Documentation. So this could be a shot in the dark, but I’m pretty sure the Instance:GetChildren() function returns an array. And the FilterDescendantInstances searches for Instances and is ignoring your array, so more than likely you’ll need to add the individual Instances into the raycastParams.FilterDescendantInstances array. You could try inserting each Instance via a loop, or possibly using the concatenation function native to Tables.
But once again, I could be wrong. I’m rather rusty with Lua.
Firstly, your snippet seems to have a lot of misnamed fields. So if this was copy & pasted from your code, those need to be fixed (e.g. FilterType should be RaycastFilterType).
Secondly, the FilterDescendantsInstances field becomes a read-only table within the RaycastParams object. So in order to change it, you have to reassign the table to it. This is definitely confusing and is not documented. The best way to get around it is by holding the filter table separately and then reassigning it to the RaycastParams anytime you change it:
local filter = {}
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = filter
-- Add something to the filter, then reassign it:
table.insert(filter, workspace)
raycastParams.FilterDescendantsInstances = filter
-- Again:
for _,v in ipairs(something:GetDescendants()) do
table.insert(filter, v)
end
raycastParams.FilterDescendantsInstances = filter