Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can string.match or other string manipulations return true?

Say I'm looking for buttons within a GUI that have names pertaining to a certain code i.e the button's name is Button_1_RD where RD is a team's code. Could I use string.match to return true in an if condition?

Like follows:

local Buttons = {
	RD1 = script.Parent.Button_1_RD,
	BD1 = script.Parent.Button_1_BD
}

for _,v in pairs(Buttons) do
	if string.match(v.Name, "RD") then
		print(RD button found!)
	end
end

1 answer

✓ Accepted answer

I don't think there's any string functions that return true. But many of them return nil and one example is string.match.

Example:

local str = "My name"
print(string.match(str, "name")) --Output: name
print(string.match(str, "Hello")) --Output: nil

1 comment

0

Thanks. I realised that if it returns nil it's functionally similar to returning false in an if condition.

This discussion is preserved as it was. New answers, comments, and votes are closed.