Repeat wait() on an item in a table

What do I want to achieve? I would like to understand how to successfully code a repeat wait() for an item in a table.

What is the issue? The repeat wait() on the second to last line is not working.

I tried looking on Youtube but couldn’t find any tutorials that focused on my specific problem. I also looked through the DevForum and still found nothing.

The ‘Times’ Table consists of texts for a TextLabel in the StarterGui. The repeat wait() will be used to change the fog for nighttime and such. The code is in a script inside the ServerScriptService.

local Times = {
	"6:00",
	"6:30",
	"7:00",
	"7:30",
	"8:00",
	"8:30",
	"9:00",
	"9:30",
	"10:00",
	"10:30",
	"11:00",
	"11:30",
	"12:00",
	"12:30",
	"1:00",
	"1:30",
	"2:00",
	"2:30",
	"3:00",
	"3:30",
	"4:00",
	"4:30",
	"5:00",
	"5:30",
	"6:00",
	"6:30",
	"7:00",
	"7:30",
	"8:00",
	"8:30",
	"9:00",
	"9:30",
	"10:00",
	"10:30",
	"11:00",
	"11:30"

}

for i, v in ipairs(Times) do
	
	print(i)
	print(v)
	
	wait(2)

	TimeDialogue:FireAllClients(v)
	
end

--

repeat wait() until Times(i) == 5

game.Lighting.FogEnd = 15

1 Like

Try replacing:

for i, v in ipairs(Times) do
	
	print(i)
	print(v)
	
	wait(2)

	TimeDialogue:FireAllClients(v)
	
end

--

repeat wait() until Times(i) == 5

game.Lighting.FogEnd = 15

With this:

for i, v in ipairs(Times) do
	
	print(i)
	print(v)
	
	wait(2)

	TimeDialogue:FireAllClients(v)
	
repeat wait() until Times(i) == 5

game.Lighting.FogEnd = 15

end

Replace

for i, v in ipairs(Times) do
	
	print(i)
	print(v)
	
	wait(2)

	TimeDialogue:FireAllClients(v)
	
end

--

repeat wait() until Times(i) == 5

game.Lighting.FogEnd = 15

with

for i, v in ipairs(Times) do
	
	print(i)
	print(v)
	
	wait(2)

	TimeDialogue:FireAllClients(v)
	
    repeat wait() until Times[i] == 5
end

--


game.Lighting.FogEnd = 15

You’re trying to pass an argument into i instead of getting an index.

1 Like

i think you should use task.wait() instead of wait() (not a fix just a recommendation)

1 Like

the “wait” in your first loop is yielding. It will wait for all of your Times to go through, and then repeat wait.

Try:

local CurrentTime = 0
task.spawn(function()
for i, v in ipairs(Times) do
	print(i)
CurrentTime = i;
	print(v)
	
	task.wait(2)

	TimeDialogue:FireAllClients(v)
        end
end)
--

repeat task.wait() until Times(CurrentTime) >= 5 -- // or just replace Times(CurrentTime) with just CurrentTime, if you want it to end after the fifth time movement

game.Lighting.FogEnd = 15
1 Like

I think you are right and task.wait() is way too fast. task.wait(0.33) is as fast as I would ever go.

2 Likes

task.wait() has no lag so thats why it seems a bit faster

2 Likes

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