The title already explains what I mean! If anyone can help, please tell me how to do this! Thanks!!!
2 Likes
This seems like a problem of https://xyproblem.info/. Why do you need the tag to be “not case sensitive”? There’s most likely a better solution.
2 Likes
Assuming you’re trying to fetch a case sensitive tag using a lowercase queue:
local function getTags(object: Instance, queue: string): {string}
queue = queue:lower()
local results = {}
for _, tag: string in pairs(object:GetTags()) do
if tag:lower() == queue then table.insert(results, tag) end
end
return results
end
local function getTag(object: Instance, queue: string): string?
return getTags(object, queue)[1]
end
--example usage
local object = workspace.Baseplate
object:AddTag("FooBar")
print(getTag(object, "foobar")) --FooBar
You could definitely use a coroutine iterator here instead to save on performance
Turn getTags()
into an iterator so it can stop the loop early when the desired result is already found
--!strict
local function getTags(object: Instance, queue: string): () -> string
queue = queue:lower()
return coroutine.wrap(function()
for _, tag: string in object:GetTags() do
if tag:lower() == queue then
coroutine.yield(tag)
end
end
end)
end
local object = workspace.Baseplate
object:AddTag("FooBar")
print( getTags(object, 'foobar')() ) --FooBar
1 Like