How to check if theres more string after a string?

This may seem confusing, but im gonna try my best to explain it.

I have a script that adds particles from the script to a players character in all of the body parts, and I have a system for that, where you put the name of the aura you have, then check if “Aura” comes after it in the string.
The script:

for i,v in pairs(char:GetChildren()) do
		if v:IsA("BasePart") and v.Name ~= humrp.Name then
			local particle = script:WaitForChild(auratype.."Aura"):Clone()
			particle.Parent = v
			particle.Enabled = true
		end
	end

It works perfectly, but I want to know how to do it if I had 2 particles of the same name in the script. If I put 2 particles in the script it only adds the first one. So I wanted to add something after “Aura” to distinguish what part of the aura the particle would be.

image

This is what I have, and I want to see how I can make it detect anything after the word “Aura” in the name of the particle. So for the “StormAura”, see if theres anything after it, which there is. “Cloud” and “Lightning”. I think you get the point. How do I do this?

You can do this by using string patterns and the string.match function.

Here is an example:

local Pattern = "%w+Aura(%w*)"

local Str_1 = "StormAura"
local Str_2 = "StormAuraLighting"

local Match_1 = string.match(Str_1, Pattern)
local Match_2 = string.match(Str_2, Pattern)

warn(Match_1, Match_2)  -- outputs: "", "Lighting"

The patterns contains three parts, the first part is any word before the word “Aura”, the second is the word “Aura” itself, and the third is the capture (%w*), where %w represents any other Alphanumeric character after the word “Aura” and the star * is to match zero or more of these characters.

You can learn more about string patterns on this documentation page.

string.find

local function getAura(auratype)
    for i, v in pairs(script:GetChildren()) do
        if v:IsA("Particle") and string.find(v.Name, "Aura") and string.find(v.Name, auratype) then
            return v
        end
    end
end

Thanks.

You can use string.match to match the pattern at the end of the string.
local string = “StormAuraCloud”

if string.match(string, “Aura$”) then
print(“match!”)
end