I’m using a for loop to loop through the entire workspace to find surfaceGuis named “Prompt” but it takes a while as it has to loop through the entire workspace. Is there a way to just search for surface gui or something?
code:
while true do
for i, prompt in pairs(game.Workspace:GetDescendants()) do
if prompt.ClassName == "SurfaceGui" then
if prompt.Name == "Prompt" then
local shownPrompt = PromptModule.CheckShowPrompt(player, prompt)
end
end
task.wait()
end
end
The issue with using FindFirstChild for this is as the name suggests, it finds the first, and only the first child pertaining to the criteria given, in this case the name.
It may be worth your time to create a Folder in workspace and place the objects in there. Then you can loop through that folder rather than the entire workspace.
Additionally if you just wanted to search for SurfaceGuis, you could do if prompt:IsA(“SurfaceGui”), but I’m unsure if that would make the entire thing quicker as it looks like the reason it’s taking so long is because it’s searching the entire workspace. You could if you wanted to store all of the prompts in a table as well, and then loop through that table.