How to change leaderstat value with an in pairs?s

Hello, i have an in pairs loop that loops through buttons in a UI and then when a button is clicked, it will get the name of that button, then it will check the leaderstats if there is something with the same name as that button and change it. but i cant seem to figure out how to do this.

here is my code:

for i, Button in pairs(Frame:GetChildren()) do
	
	if Button:IsA("TextButton") then
		
		Button.MouseButton1Click:Connect(function()
			
			if player.leaderstats.(Button.Name).Value <=0 then
				return nil
			end
			

here is the error

try this

for i, Button in pairs(Frame:GetChildren()) do
    if Button:IsA("TextButton") then
        Button.MouseButton1Click:Connect(function()
            if player.leaderstats:FindFirstChild("Button.Name").Value <= 0 then
                return end
            end
        end)
    end
end

It just says expected e of got end

Try this (not tested)

local Frame --Your frame path here
local player = game.Players.LocalPlayer

for _, Button in ipairs(Frame:GetChildren()) do
   if Button:IsA("TextButton") then
      Button.MouseButton1Click:Connect(function()
          if player.leaderstats:FindFirstChild(Button.Name).Value <= 0 then
             return nil
         end
     end)
   end
end

You first need to check if a leaderstats with the same name exist because if it doesn’t it will give an error.

local player = game.Players.LocalPlayer

for _, Button in ipairs(Frame:GetChildren()) do
   if Button:IsA("TextButton") then
      Button.MouseButton1Click:Connect(function()
          if player.leaderstats:FindFirstChild(Button.Name) then
             if player.leaderstats[Button.Name].Value <= 0 then
                return nil
             else
                -- leaderstats exists and the value is greater than 0
             end
         end
     end)
   end
end

Yeah, sorry I wrote it quickly and did not test it or check it, thanks for telling me.