Why is nothing being added to FilterDescendantsInstances?

I can’t figure out why nothing is being added to FilterDescendantsInstances. Am I stupid?

local Whitelist = {}

for _,object in pairs(CollectionService:GetTagged("Selectable")) do
	table.insert(Whitelist,object)
end

local rayParams = RaycastParams.new()
rayParams.FilterType = Enum.RaycastFilterType.Include
rayParams.FilterDescendantsInstances = Whitelist

print(rayParams.FilterDescendantsInstances) -- The table is empty for some reason??

EDIT: I found the solution. It has something to do with the game not loading completely. game.Loaded:Wait() didn’t work, so I just used task.wait() at the beginning of the script and it started working fine.

1 Like

Just to know what the problem is, make a print statement with the object’s name like this:

for _,object in pairs(CollectionService:GetTagged("Selectable")) do
    table.insert(Whitelist, object)
    print("Added object to Whitelist:", object.Name) -- Add this line for debugging
end

It does not print anything. Huh. I’m sure I added objects to the “Selectable” tag, though.

1 Like

Make sure it’s spelled correctly, or if there are instances that got tagged.

1 Like

Everything is spelled correctly. I have no clue.

1 Like

You are propably using the plugin for it. Mind sending a screenshot of the window of the tag?

2 Likes

image
They are all tagged with “Selectable”.

2 Likes

These are my only 3 questions now, else i got no clue.
Is that the plugin you use? If not, you should probably use it, here: Tag Editor - Roblox
Is there a space after that word?
What is getting tagged?

2 Likes
  1. I did use the plugin. The objects are all tagged with “Selected”, so I don’t think that’s an issue.
  2. There is no space.
  3. I’m tagging objects in this folder:
    image
    I think I might just loop through the folder instead of using CollectionService.
    EDIT: Nevermind, even that doesn’t work. What is happening?
1 Like

Ah, then just make it folder:GetChildren() , where ever folder is located at.

1 Like

I don’t know what’s happening. GetChildren() doesn’t work either.

1 Like

You did reference the folder and not CollectionService right?

1 Like

Yes. There is no reason for it to be not working, yet it doesn’t. I’m gonna post my entire script.

local UserInputService = game:GetService("UserInputService")
local CollectionService = game:GetService("CollectionService")
local TweenService = game:GetService("TweenService")

local Camera = workspace.CurrentCamera
local SelectedItem = nil

local list = {}

for _,object in pairs(game.Workspace.Ores:GetChildren()) do
	table.insert(list,object)
	print("Added object to Whitelist:", object.Name)
end
print(list)

local rayParams = RaycastParams.new()
rayParams.FilterType = Enum.RaycastFilterType.Include
rayParams.FilterDescendantsInstances = list

print(rayParams.FilterDescendantsInstances)

local function MouseRaycast()
	local mousePos = UserInputService:GetMouseLocation()
	local mouseRay = Camera:ViewportPointToRay(mousePos.X,mousePos.Y)
	local raycastResult = workspace:Raycast(mouseRay.Origin,mouseRay.Direction*100,rayParams)
	
	return raycastResult
end

UserInputService.InputBegan:Connect(function(input,processed)
	if processed then -- idk
		return
	end
	
	if input.UserInputType == Enum.UserInputType.MouseButton1 then -- on click
		local result = MouseRaycast() -- creates the mouse raycast
		if result and result.Instance then
			local item = result.Instance -- item is selectable
			
			if item == SelectedItem then -- mining
				local tweenInfo = TweenInfo.new(.2,Enum.EasingStyle.Bounce)
				local goal = {CFrame = SelectedItem.CFrame + Vector3.new(0,-1,0)}
				local tween = TweenService:Create(SelectedItem, tweenInfo, goal)
				tween:Play()
				
				local goal2 = {CFrame = SelectedItem.CFrame + Vector3.new(0,1,0)}
				local tween2 = TweenService:Create(SelectedItem, tweenInfo, goal2)
				tween2:Play()
			elseif not SelectedItem then -- (Select)
				SelectedItem = item
				local Highlight = Instance.new("Highlight")
				Highlight.FillTransparency = 1
				Highlight.Parent = SelectedItem
			elseif item ~= SelectedItem then
				SelectedItem.Highlight:Destroy()
				SelectedItem = item
				local Highlight = Instance.new("Highlight")
				Highlight.FillTransparency = 1
				Highlight.Parent = SelectedItem
			end
		elseif SelectedItem then -- (Unselect) if it is not selectable and if something is selected then unselect
			SelectedItem.Highlight:Destroy()
			SelectedItem = nil
		end
	end
end)
1 Like

Ok my only last guess: What type of script is it and where is it located?

1 Like

It’s a localscript located in StarterPlayerScripts.

I’ve tried replicating the problem, I will investigate it further on until I find a solution for you.

So since i am on my phone now, I thought of an idea. Just make a random server script somewhere and paste the for loop there and see if it prints anything there besides an empty table

My best guess is that the collection hasn’t properly loaded yet, assuming that the localscript finishes loading (and runs) before the “Selectable” tagged instances fully loads.
You could use game.Loaded:Wait() as the first line in order to wait for the game to fully load.

When I use that in a LocalScript, nothing runs.

It works in a server script but not a local script. I’m so confused.