TextLabel not appearing the same for everyone

Hello. I made a sort of date system counts up from January of a given year, each month being 25 seconds long.

local dateLabel = script.Parent
local startingYear = 2017
local months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}

while true do
	for i, v in pairs(months) do
		dateLabel.Text = v..", "..startingYear
		wait(25)	
	end
	
	startingYear = startingYear + 1
end

It works fine. Except when someone else joins my game, their date goes to the starting point (in this case it’s January 1, 2017), even though for me it’s gotten way past that. Is there something I’m doing wrong?

This is a server script by the way. The screengui it’s in has it’s ResetOnSpawn property set to false.

I’m guessing what is happening is you end up with multiple copies of this server side script because it is a descendant of a gui which is cloned into a player’s PlayerGui everytime one joins. This would explain the offset dates for late joining players. Likely you will want to approach the problem a different way. My suggestion would be to have a server side script located in ServerScriptService which modifies the Value property of a StringValue located in ReplicatedStorage. Then in a local script parented to the gui that will be cloned into every Player’s PlayerGui, add some code which listens for changes to that StringValue. Example Code:

--ServerScript in ServerScriptService
local startingYear = 2017
local months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
while true do
   for _, monthName in pairs(months) do
      game.ReplicatedStorage.CurrentDate.Value = monthName..", "..startingYear
      wait(25)
   end
   startingYear = startingYear + 1
end
--LocalScript in the gui to be cloned
function updateDateLabel()
   script.Parent.Text = game.ReplicatedStorage.CurrentDate.Value
end

game.ReplicatedStorage.CurrentDate.Changed:connect(updateDateLabel) --Connect an event listener
updateDateLabel() --Call the update function once so the label is accurate when the gui is cloned instead of having to wait for the next update

(May be a few typos in there)

1 Like