String.match isn't working

I’m making a crafting Gui, and I have several buttons, each called Craftingslot1, Craftingslot2, etc.
To find what number the player clicked I tried to use string.match.

for i, button in pairs(script.Parent:GetChildren()) do
	print(button.Name)
	if button.ClassName == "ImageButton" then
		button.MouseButton1Click:Connect(function()
			print(button.Name)
			local button_number = string.match(button.Name, %d)
		end)
	end
end

However, I get the error on the line
local button_number = string.match(button.Name, %d)
and it says “expected identifier when parsing expression, got ‘%’”.
According to the dev wiki, %d takes the numbers out of the string

its a string. NOT %. Got it??? So do

local button_number = string.match(button.Name, "things here")

Silly, you forgot to add double quotes around the d thing.

string.match(button.Name, "%d")
2 Likes

No, you can use %d in order to find a number in the string.

1 Like