Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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!

0
okay thanks jacobian65 19 — 4y
Ad

Answer this question