CollectionService tags returning StarterGui elements instead of PlayerGui

Hi everyone,

I’m running into a problem with CollectionService and tagged GUI elements in a local player’s PlayerGui. Here’s the situation:

  • I have some GUI elements in StarterGui that are tagged using CollectionService.
  • These GUI elements (and the tags) replicate correctly to the player’s PlayerGui.
  • I want to manipulate the GUI in PlayerGui only (e.g., highlight buttons, change visibility that have that certain tag).

The issue is that when I call CollectionService:GetTagged("TagName") on the client through my ModuleScripts which are immediately required with a ModuleLoader, it returns the original instances in StarterGui and not a single copy in PlayerGui, even though the tags themselves also exist on the PlayerGui copies.

I already wait for the game to be loaded in the ModuleLoader and wait for the PlayerGui too.

So my question is:

  • Is there a way to reliably get only the PlayerGui instances of tagged objects with CollectionService?
  • Or is there a recommended pattern to work with GUI tags that exist in PlayerGui without accidentally referencing StarterGui?

Any guidance or best practices for this situation would be much appreciated!

Thanks in advance!

EDIT

I discovered that adding a simple task.wait(5) in my ModuleLoader makes it work, the PlayerGui elements are fully available by then, and CollectionService:GetTagged returns PlayerGui instances.

However, this feels like a hack. Is there a proper or reliable way to wait until PlayerGui is fully replicated before loading modules that depend on it?

Don’t use bloatware or whatever your ModuleLoaders are, and have GUI in replicated first instead, instantly parented to PlayerGui on client.
StarterGui honestly sucks.

Thank you, moving my ScreenGui from ReplicatedFirst to the PlayerGui fixed the problem

You could address the race condition by adding existing tagged parts and then listening for additional tagged parts with CollectionService:GetInstanceAddedSignal().

Instance:IsDescendentOf() can be used to filter out all but parts within PlayerGui.

local function addtagged(part)
  if not part:IsDescendantOf(PlayerGui) then return end
  ...
end
for _,part in CollectionService:GetTagged("TagName") do addtagged(part) end
CollectionService:GetInstanceAddedSignal("TagName"):Connect(addtagged)