Invalid argument #1 to 'match' (string expected, got table)

OK, im currently doing that. (charcharchar)

Then there’s no issue of duplication

bots.rbxl (153.2 KB)

Here’s your place file back with a couple changes.

I added a “NPC” tag to the Builder model template

So that now we can get NPCs by tag

local CollectionService = game:GetService("CollectionService")

local scrollingFrame = script.Parent
local npcLabelTemplate = script.NPC

local function onNpcAdded(npc)
	if not npc:IsDescendantOf(workspace) then
		return
	end

	local npcLabel = npcLabelTemplate:Clone()
	npc.Humanoid.Died:Once(function()
		npcLabel:Destroy()
	end)
	local survivedTextLabel = npc.Head.ROUNDS.SURVIVED
	local function updateLabel()
		local roundsSurvived = tonumber(npc.Head.ROUNDS.SURVIVED.Text:match("%d+"))
		if roundsSurvived then
			npcLabel.Text = `{roundsSurvived}: {npc.Name}`
			npcLabel.LayoutOrder = -roundsSurvived
		end
	end
	
	npc.Head.ROUNDS.SURVIVED:GetPropertyChangedSignal("Text"):Connect(updateLabel)
	updateLabel()
	npcLabel.Parent = scrollingFrame
	print("Added")
end

for _, npc in CollectionService:GetTagged("NPC") do
	onNpcAdded(npc)
end

CollectionService:GetInstanceAddedSignal("NPC"):Connect(onNpcAdded)

I also added a UIListLayout to the ScrollingFrame in order to allow text labels to show up in a list.
Now a new textlabel is created for each NPC, and updated based on the textlabel above their head.

Could you give me an .rbxl of your version?

It’s in the post above already :slight_smile:

Oh, sorry! I didnt see it. (char)

Thank you so much, it works! (Char)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.