Trying to loop through a table in order

Im creating a school bell gui and i need to be able to go through all the the classes listed in a table in a module script.

the current code i have 1. doesn’t work, and 2. i probably used it wrong.

local textLabel = script.Parent

function typeWrite(object,text)
	for i = 1,text,1 do
		object.Text = string.sub(1,i)
		wait(0.05)
	end
end

game.ReplicatedStorage.School.OnServerEvent:Connect(function(player, mode)
	local classes = require(game.ServerScriptService.ConfigureClasses)
	if player:GetRankInGroup(9822548) >= 251 then
		if mode == "ADay" then
			local classesToday = classes.ClassesInADay
			local timeForThisClass = classes.TimeForADayClasses
			
		elseif mode == "BDay" then
			local classesToday = classes.ClassesInBDay
			local timeForThisClass = classes.TimeForBDayClasses
			
		elseif mode == "EarlyDissmissal" then
			local classesToday = classes.ClassesInEarlyDissmissalDay
			local timeForThisClass = classes.TimeForEarlyDissmissalClasses
			
			for i = 1,classesToday,1 do
				typeWrite(textLabel, "Current Class: "..i)
			end
		end
	end
end)

modulescript:


local config = {}

config.ClassesInADay = {"English, Science, Etc"}
config.TimeForADayClasses = 60
config.ClassesInBDay = {"English, Science, Etc"}
config.TimeForBDayClasses = 60
config.ClassesInEarlyDissmissalDay = {"English, Science, Etc"}
config.TimeForEarlyDissmissalClasses = 30

return config
1 Like

Why don’t you just use

for i, v in ipairs(classesToday) do

end
1 Like

would this give the clases in the order they are listed in the modulescript?

I’m not sure if you’re looking for this? (Edited)

1 Like

Yes, but you can add a lot of classes and I would need to loop through the classes to get them 1 by 1 after 60 seconds or 30 seconds. so if i used table.find then I would have to have a way to detect how many items are in the table.

# return values in the table, so do this.

for i = 1, #classesToday do
	typeWrite(textLabel, "Current Class: "..classesToday[i])
end

Edited again.

why can’t you just use ipairs?

Mk. Didn’t work. I got the error

invalid 'for' limit (number expected, got string)

how would i do this with ipairs?

for index, class in ipairs(classesToday) do
    -- do stuff. class is "English", "Science" etc. and index is the position of the value in the table
end

Didn’t work. Got the error

invalid 'for' limit (number expected, got string)

did i u se this correctly?

for index, class in ipairs(classesToday) do
				typeWrite(textLabel, "Class is "..class)
			end

prob not

Can you share the updated script? It’d be helpful.

Try this.

function typeWrite(Object, Text)
	Object.Text = ""
	local Text2 = Text
	for i = 1, #Text2 do
		Object.Text = string.sub(Text2, 1, i)
		wait(0.05)
	end
end

– Yield

Which one do I use? you sent 2. :confused:

This one, the first one is your without editing.

1 Like

Ok. Do i include the “- Yield” part?

This works but not how I wanted. I want it to list item 1. item 2. etc after a certain amt of time

Your table is not split properly. Please split all the values.

Where do i control the wait before tywriting what the next class is?

Right now it just immediantly types it