The aim here is to make a countdown that displays itself on the players GUI. for that reason this script is in StarterGui -> ScreenGui -> TextLabel
local CurrentTime = os.time() local EndTime = CurrentTime + 60 -- 60 seconds past CurrentTime local TimeLeft = EndTime - CurrentTime -- Time remaining on the clock Player = game.Players.LocalPlayer --for adding gamepass later on, ignore local MarketplaceService = game:GetService("MarketplaceService") --for adding gamepass later on, ignore while true do -- while loop if TimeLeft == 0 or os.clock == EndTime then --end of countdown script.Parent.Text = "End of countdown." -- script.Parent is a TextLabel else script.Parent.Text = tostring(TimeLeft) -- script.Parent is a TextLabel local TimeLeft = EndTime - os.time end end
Instead of displaying the correct amount of time, counting down in seconds, it displays 60
I exchanged the while true loop for a for loop, and the resulting loop looks like that
Player = game.Players.LocalPlayer --for adding gamepass later on, ignore local MarketplaceService = game:GetService("MarketplaceService") --for adding gamepass later on, ignore for i = 60, 0, -1 do script.Parent.Text = string.format("Countdown ends in %i seconds.", i) wait(1) if i == 0 then script.Parent.Text = "countdown ended!" break end end