You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
An NPC-only leaderboard for rounds survived.
What is the issue? Include screenshots / videos if possible!
It does not work, instead giving me an error.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Different arguments, yes.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local names={"builder","man","guy","brick"}
local npc=string.match(game.Workspace:GetChildren(),names[math.random(1,#names)],1)
script.Parent.Text=game.Workspace:WaitForChild(npc).Name
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
:GetChildren returns a table, and string.match requires a string for the first argument. what are you trying to do? do you want to get a child of workspace which has “builder”, “man”, “guy”, or “brick” in its name?
Basically, bots spawn in a random pattern inside of a box and they have a “ROUNDS SURVIVED” counter above their heads, they place randomly every 1-5 seconds blocks with random colors, shapes and sizes. Rocks spawn every half-minute, if they touch the rocks, they are killed and their counter is reset, if a block touches the rocks, its flinged and unanchored.
local names={"builder","man","guy","brick"}
local npc
local randomName = names[math.random(1,#names)]
for _,child in workspace:GetChildren() do
if string.match(child.Name,randomName,1) then
npc = child
end
end
script.Parent.Text=npc.Name
At this point, just tag the NPCs or parent them to a folder. It’s more efficient than brute-forcing all children of the workspace for a particular phrase
Thank you. However, now theres one more step;
I need to get all 24 Builders in there, without any duplicates. There is also the problem of getting the number of rounds they survived.
Use a permuting algorithm to generate an NPC per permutation of the available words. This will naturally prevent you from generating an NPC with an existing name. Use a generator approach if you need to create NPCs at different times, but know that the generator will eventually exhaust if the NPCs with assigned names can be deleted (consider object-pooling). You can re-create the generator to start the process over.
The number of rounds a particular NPC survives should not be associated with their name, but the instance itself