Variable won't change in function

In a script, I’m trying to collect data from another server script that has an in-game countdown and change a variable to that data. However, the variable remains nil forever. Any way to fix this?

local t

function Countdown(num)
	local connection
	connection = game:GetService("RunService").Heartbeat:Connect(function()
		num = game.ServerScriptService.RoundMaker:GetAttribute("TimeLeft")
		if num == 0 then
			connection:Disconnect()
		end
		return num
	end)
end

t = Countdown(t)

It turns out, based on the output, the function doesn’t run until after the repeat loop after is ran through. So there’s some additional information.

And because the repeat loop runs first, all I had to do was put the t = function line in the repeat loop.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.