I have this script that tags assets using CollectionService
so that my loading screen knows what to preload.
local CollectionService = game:GetService("CollectionService")
function isAsset(v)
if v:IsA("Decal") or v:IsA("ImageLabel") or v:IsA("ImageButton") or v:IsA("MeshPart") or v:IsA("SpecialMesh") or v:IsA("Texture") or v:IsA("Sound")then
return true
end
return false
end
for i,v in pairs(workspace:GetDescendants()) do
if isAsset(v) then
CollectionService:AddTag(v, "Asset")
end
end
for i,v in pairs(game.ReplicatedStorage:GetDescendants()) do
if isAsset(v) then
CollectionService:AddTag(v, "Asset")
end
end
for i,v in pairs(game.StarterGui:GetDescendants()) do
if isAsset(v) then
CollectionService:AddTag(v, "Asset")
end
end
for i,v in pairs(game.MaterialService:GetChildren()) do
if v:IsA("MaterialVariant") then
CollectionService:AddTag(v, "Asset")
end
end
--print("tagged assets")
game.ReplicatedStorage.GotAssets.Value = true
I know using :GetDescendants()
on the workspace is horrendous for preformance, so I’m wondering: Is there a way to filter what it returns? Or at least a more efficient way of looping through everything?