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.
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
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?
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)
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.