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)
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
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.