How to Change all textlabel's text to text -1 every second at the same time

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I think title is enough to describe it but.
    I am trying to change all text labels at the same time
  2. What is the issue? Include screenshots / videos if possible!
    other Texts aren’t changing until first text reach 0
local Gui = script.Parent
local Frame = Gui:WaitForChild("Frame")
local DailyRewardsModule = require(game:GetService("ReplicatedStorage"):WaitForChild("Modules"):WaitForChild("DailyRewards"))

for i , v in pairs(Frame:GetDescendants()) do
	if v:IsA("TextLabel")  then
		v.Text = DailyRewardsModule[v.Name]["ClaimTime"]
		while tonumber(v.Text) >0 do
			v.Text = v.Text - 1
			task.wait(1)
		end
	end
end

I am not sure if I explained it good so, here is a video of the issue

Try this:


local Gui = script.Parent
local Frame = Gui:WaitForChild("Frame")
local DailyRewardsModule = require(game:GetService("ReplicatedStorage"):WaitForChild("Modules"):WaitForChild("DailyRewards"))


local function TickTime(v)
	v.Text = DailyRewardsModule[v.Name]["ClaimTime"]
	while tonumber(v.Text) >0 do
		v.Text = v.Text - 1
		task.wait(1)
	end
end


for i , v in pairs(Frame:GetDescendants()) do
	if v:IsA("TextLabel")  then
	coroutine.wrap(TickTime)(v)
	end
end

Let me know if Errors happen or it doesn’t work!

1 Like

it works! but I am confused about how it works or why my code didn’t worked can you explain please?

Of course! coroutine.wrap allows us to call functions without Yielding for them! Where your script, was waiting for one gift with task.wait(1) to finish before starting the next one. coroutine.wrap just called all the functions at the same time, to start together

Edit: You can learn more here: coroutine.wrap

1 Like

Thanks! for explaination and for the documantion. I really appreciate it

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.