Problem setting a stringvalue

Hi everyone!
I wanted to make a countdown for my game, so i did a script that changes the value every second!
What is wrong in my script?

local replistor = game:GetService("ReplicatedStorage")
local repcount1 = replistor:WaitForChild("CountDown")
local countdownduration = 30
local gui = game:GetService("GuiService")
local countdownGUI = gui:WaitForChild("CountDownGUI")

function countdownupdate()
  	for t = countdownduration,1,-1 do
	   	repcount1.Value = "Intermission:" ..t.. " seconds left!"
 	end
end)

spawn(countdownupdate)
1 Like

Modules always should return 1 value. Is that the whole code? If not, the full code would be useful.

2 Likes

Every module needs to return something. For example:

local module = {}

return module
1 Like

This isn’t on a module script
I think i showed the wrong output error, did i?

1 Like

Oh then you must have a module somewhere that is not returning something. That should be fixed as well.

1 Like

If that is the case, disable the other scripts and remember to enable them later.

The problem here is that you don’t have a wait, which results in the countdown going too fast about 1/30th of a second.

If you are sure this isn’t on the module, try:

function countdownupdate()
  	for t = countdownduration,1,-1 do
	   	repcount1.Value = "Intermission:" ..t.. " seconds left!"
        wait(1)
 	end
end)

Here’s some additional information on modules: ModuleScript | Documentation - Roblox Creator Hub

2 Likes

Yeah, i will solve this asap, i know exactly the error, i’m just focusing on the countdown by now, or i will have a lot of things to do

1 Like

Yeah add the wait(1) like @SilentsReplacement said and it should be good.

1 Like

It still doesn’t work.
Is the spawn function affecting it?

1 Like

It shouldn’t, do you have any errors? and what is local repcount1 = replistor:WaitForChild("CountDown") ?

1 Like

it’s the stringvalue i put on replicated storage

1 Like

Then you have no problem, you never set the value of it to some gui so you can see the changes. Is countdownGUI a Screen Gui?

1 Like
local module = {}
   local replistor =  game:GetService("ReplicatedStorage")
   local repcount1 = replistor:WaitForChild("CountDown")
   local countdownduration = 30
   local gui = game:GetService("GuiService")
   local countdownGUI = gui:WaitForChild("CountDownGUI")

   function countdownupdate()
  	for t = countdownduration,1,-1 do
	   	repcount1.Value = "Intermission:" ..t.. " seconds left!"
 	end
end)

   spawn(countdownupdate)
return module

This should work if it’s a module script.

sorry for the edits. I’m on mobile atm

Yes!
and there’s a “MapCountDown” text i put to show it!
And the string value doesn’t update!

The string value does update. You can set the text to the value and see the text updating every loop.

local function countdownupdate()
  	for t = countdownduration,1,-1 do
	   	repcount1.Value = "Intermission:" ..t.. " seconds left!"
        countdownGUI.MapCountDown.Text = repcount1.Value
        wait(1)
 	end
end)

Instead of using a variable, you could change the text directly with the same script. Add this script into a TextLabel and add the TextLabel to whatever UI you are using, and then position the text how you want:

local replistor = game:GetService("ReplicatedStorage")
local repcount1 = replistor:WaitForChild("CountDown")
local countdownduration = 30
local gui = game:GetService("GuiService")
local countdownGUI = gui:WaitForChild("CountDownGUI")

function countdownupdate()
  	for t = countdownduration,1,-1 do
	   	repcount1.Text= "Intermission:" ..t.. " seconds left!"
 	end
end)

spawn(countdownupdate)

That should generally do it, but of course, people could more easily fix your code if you can put the rest of your code in there, and where the script is and such.

1 Like

But the thing is, it the server needs to know the time…

I fixed it!
I needed to fix the module script that was connected to the same script…
Everything is ok now!