Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how to make countdown timer changes text color after reaching last 10 seconds?

hi there, I am trying to make my countdown timer to change color from white to red and red to white for the last 10 seconds so that the player will know the timer is about to end soon. just like in Tower of Hell. here is the screenshot.

currently, my code looks like this

 for i = GameLength, 0, -1 do
    local minutes = math.floor(i/60)
    local seconds = math.floor(i%60)
    Status.Value = (string.format("%i:%.2i", minutes, seconds))
     wait(1)

any idea of how to modify the code so that the last 10 seconds has changeable text color for the timer?

1 answer

✓ Accepted answer

If this script is from the server, fire a remote function from the script and receive it on the client in a Local Script (usually in the GUI).

Example:

-- Server Script
for i = GameLength, 0, -1 do
	local minutes = math.floor(i/60)
	local seconds = math.floor(i%60)
	Status.Value = (string.format("%i:%.2i", minutes, seconds))
	wait(1)

	-- Check if there is 10 seconds left
	if Status.Value == "00:10" then
		for _, player in pairs(game.Players:GetPlayers()) do
			game.ReplicatedStorage.ChangeTextColor:InvokeClient(player)
		end
	end
end

-- Local Script
game.ReplicatedStorage.ChangeTextColor.OnClientInvoke = function()
	script.Parent.Parent.YourGui.TextLabel.TextColor3 = Color3.fromRGB(255,0,0)
end

I hope this helped!

1 comment

0

okay thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.