I am trying to use the tag names used in CollectionService to set some variables and I am having a hard time using string.match to do this.
each instance is tagged with three tags like so:
“Spawner”
“Type_1”
“Region_1A”
I want to be able to set some variables based on Type and Region, I wont be using the Spawner tag in this operation.
here is the code I am trying to use:
for a,b in pairs(CollectionService:GetTagged("Spawner")) do
-- apply basic settings
b.Transparency = 1
local position = b.Position
-- get all the tags and set the variables
local Tags = CollectionService:GetTags(b)
local SpawnerType
local Region
local pattern = "() _ ()"
for c,d in pairs (Tags) do
if d ~= "Spawner" then
print(c,d) -- this will print correctly
local key, val = string.match(d,pattern)
print(key,val) -- this is printing nil,nil
end
end
end
As you can see in the sample above, there are two print statements. I have added some comments. The first print does print the key and value properly for c and d. The second print statement prints nil,nil.
I am not sure why, i suspect it has something to do with the pattern i am using but bit sure.
What i want to be able to split a tag name such as “Region_1A” into: key = “Region” and value = “1A”
Thanks in advance!