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

Trying to change a TextLabel to TimeOfDay?

Asked by 4 years ago

So I have this Day/Night cycle code I made, and I was wondering what I could add to this to make it change text in a TextLabel.

Here is my code:

local interval = 0.4
local change = 0.01

while wait(interval) do
    game.Lighting.ClockTime = game.Lighting.ClockTime + change
end

Any help is appreciated!

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago
-- Client Script

local Players = game:GetService("Players") -- Player Service
local Lighting = game:GetService("Lighting") -- Lighting Service

local LocalPlayer = Players.LocalPlayer -- Our Client
local PlayerGui = LocalPlayer.PlayerGui -- Our Gui path, StarterGui clones it to here for each player.

local Gui = PlayerGui.ScreenGui -- Our Gui
local TextLabel = Gui.TextLabel -- Our Textlabel to change.

local Interval, Change = .5, .01 -- Declaring our Variables

while wait(Interval) do -- while loop.
    Lighting.ClockTime = Lighting.ClockTime + Change -- Setting new time
    TextLabel.Text = ("%s"):format(Lighting.TimeOfDay) -- Set textlabel to time.
end

:) Hope this has helped in any shape.

0
Thanks! :) Unable to test rn, but will get back when I can. matiss112233 258 — 4y
Ad
Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

This is Simple Just create a script inside the TextLabel and copy the code below into it.

game:GetService("RunService").Stepped:Connect(function() --A loop
    script.Parent.Text = "Time: "..game.Lighting.ClockTime --Changes Text of TextLabel to Clock Time
end)

Answer this question