Part of script not running when GUI element is clicked

In a nutshell, I have a script that changes the value of a variable (for a GUI system based on a module) and it’s not working. Probably missing something simple but, I’m not sure.

Script:

local module = require (game.ReplicatedStorage.Modules.Teams)
local page = 1
local Button1 = script.Parent.Button1.TextButton
local Button2 = script.Parent.Button2.TextButton
local teamselected = script.Parent["Team Lable"]
local curentpagenumber = module[page]
local TotalPages = 16

while true do
	wait(0.1)
	teamselected.Text = 'Current Team Selected: '..curentpagenumber.name..''
end

Button1.MouseButton1Click:Connect(function(player)
	if page >=1 and page < TotalPages then
		page = page + 1
		print(page)
	elseif page < 1 then
		page = 1
	else if page > TotalPages then
			page = TotalPages
		end
	end 
	
end)

is there any errors in the output?

Is the problem your connection doesn’t happen? Make the connection prior to the infinite while-loop, else it’s not being declared.

local module = require (game.ReplicatedStorage.Modules.Teams)
local page = 1
local Button1 = script.Parent.Button1.TextButton
local Button2 = script.Parent.Button2.TextButton
local teamselected = script.Parent["Team Lable"]
local curentpagenumber = module[page]
local TotalPages = 16

spawn(function()
	while true do
		wait(0.1)
		teamselected.Text = 'Current Team Selected: '..curentpagenumber.name..''
	end
end)

Button1.MouseButton1Click:Connect(function(player)
	if page >=1 and page < TotalPages then
		page = page + 1
		print(page)
	elseif page < 1 then
		page = 1
	else if page > TotalPages then
			page = TotalPages
		end
	end 
	
end)

Try this

Just that at the line where the click is detected, no matter what I put there it never runs (I tried a few other scripts, the script in that part now is more of a test.)