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

How do I make a text label's text change to the different days as time progresses?

Asked by 7 years ago

local Days = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}

game.Players.PlayerAdded:connect(function() game.Lighting.Changed:connect(function(property) if property == "TimeOfDay" then for i,v in ipairs(Days) do local minutes = game.Lighting:GetMinutesAfterMidnight() if minutes == 0 then script.Parent.Text = "Day: "..v end end end end) end)

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

You could try adding this in a local script inside the text label (assuming you already have a separate day/night script that doesn't skip any minutes):

local Days = --days table here
local DayCount = 1
game.Lighting.Changed:Connect(function(property)
    if property == "TimeOfDay" then
        local minutes = game.Lighting:GetMinutesAfterMidnight()
        if minutes == 0 then
            script.Parent.Text = "Day: " .. Days[DayCount]
            DayCount = DayCount + 1
            if DayCount > 7 then
                DayCount = 1
            end
        end
    end
end)

You also have to set the ResetOnSpawn property of the ScreenGui the label is in to false, so it does not reset the cycle when the player dies.

0
Thanks. I noticed you didn't loop through the table. DrInfinitum 4 — 7y
Ad

Answer this question