Players.bIIocky.PlayerScripts.LocalScript:14: attempt to index nil with 'Connect

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

4 Likes

Could you show your ScreenGUI hierarchy? And print what is timeValue in the localscript just so I know if it finds the instance or not (it’s nil)

1 Like

image
This is the ScreenGUI hierarchy

1 Like

Replace this with

local timeValue = replicatedStorage.Time

and this with

playerGui.timeGUI.timeLabel.Text = tostring(timeValue.Value)
2 Likes

I’ve tried this before, but got this warning in return
image

1 Like

Where are your scripts located?

1 Like

edit: nvm i msread the post
30char

1 Like

The module in located in replicatedstorage, while the localscript is located within starterplayerscripts

1 Like

Can you find the screen gui in you player’s PlayerGui through the explorer while in the game?

1 Like

yup
image

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?

Since I’m new to scripting, might you show me where to find this traceback?

The output you sent here, but show the blue messages (that’s the traceback)

gotcha

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

timeValue.Changed:Connect(updateTime)

with

timeValue:GetPropertyChangedSignal("Value"):Connect(updateTime)

Because as the name “GetPropertyChangedSignal(“Value”)” suggests, it gets a signal every time that property changes

That’s the whole script. I’ve been trying some stuff while waiting for a reply, so there may be spaces when there wasn’t in the original posted script
image

Yeah that’s it what @hannes213 said

I’ve tried this, but it yielding this as a result, which brings me back to square one.

I can find TimeGUI within the players tab, and so it is most frustrating when the script can’t find it for whatever reason.
image