I’m trying to update a GUI textlabel with a day/night cycle and timer script, but to no avail. Every time I attempt to try and do this, I get one of two errors… “Players.bIIocky.PlayerScripts.LocalScript:14: attempt to index nil with 'Connect” and “timeLabel is not a valid member of ScreenGui Players.bIIocky.PlayerGui.TimeGUI”
I’ve tried setting the itemLabel value, but instead got the same error. Any help would be appreciated.
Localscript
local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local localPlayer = players.LocalPlayer
local playerGui = localPlayer:WaitForChild("PlayerGui")
local timeValue = replicatedStorage.Time.Value
local timeGui = playerGui:WaitForChild("TimeGUI")
local timeLabel = timeGui:WaitForChild("timeLabel")
local function updateTime()
playerGui.timeGUI.timeLabel.Text = tostring(timeValue)
print(timeLabel.Text)
end
timeValue.Changed:Connect(updateTime)
Server script
local module = {}
local starterGui = game:GetService("StarterGui")
local timeGui = starterGui.TimeGUI
local replicatedStorage = game:GetService("ReplicatedStorage")
local timeValue = replicatedStorage.Time
local Players = game:GetService("Players")
local MA = "AM"
local RunService = game:GetService("RunService")
local LG = game:GetService("Lighting")
local sunTime = 0
local function ChangeAM(num)
if num <= 12 then
MA = "AM"
elseif num > 12 then
MA = "PM"
end
if num % 3 == 0 then
for i = sunTime,num,0.05 do
RunService.Heartbeat:Wait()
sunTime = i
LG.ClockTime = sunTime
end
end
end
local function FormatHour(num)
if num > 12 then
return tostring(num - 12)
else
return tostring(num)
end
end
local function FormatNumber(num)
if num <= 9 then
return "0"..tostring(num)
else
return tostring(num)
end
end
local function FormatDay(num)
num = num + 1
local days = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}
return days[num]
end
function module:StartTime()
while true do
for d = 0,6,1 do
for h = 1,24,1 do
ChangeAM(h)
for m = 0,59,1 do
for s = 0,59,1 do
local formattedTime = FormatHour(h)..":"..FormatNumber(m)..":"..FormatNumber(s).." "..MA
local formattedDay = FormatDay(d)
game.ReplicatedStorage.Time.Value = formattedTime
game.ReplicatedStorage.Day.Value = formattedDay
RunService.Heartbeat:Wait()
end
end
end
end
end
end
return module
That’s odd, I did the following in a localscript inside StarterPlayerScripts:
local players = game:GetService("Players")
local localPlayer = players.LocalPlayer
local playerGui = localPlayer:WaitForChild("PlayerGui")
local timeGui = playerGui:WaitForChild("TimeGUI")
print(timeGui)
And it worked fine, found the GUI with no issue, can you show the whole error traceback?
Could you send the whole script, or at least the line it shows in the error (line 16)? It says the error is in line 16, but the code you sent only goes until line 12.
timeValue in your local script should be defined as replicaredStorage.Time, not replicatedStorage.Time.Value, because .Value gives you a number, and number.Changed isn’t really a thing in lua. Then you’d also want to replace the line