im trying to make a map changer after each round in order A-Z without math.random so i tried it by indexing through the MapsToLoad folder but somehow it skips a child of the MapsToLoad so it will be like B-D-C-A not A-B-C-D
heres the code
local SS = game:GetService("ServerStorage")
local mtl = SS.CustomMaps:GetChildren() --mapstoload
local c = 1 -- this variable act as an index
script.Parent.RegenControl.Signal.Changed:Connect(function()
wait(5)
local mtu = workspace.LoadedMaps:GetChildren() --mapstounload
for _, m in pairs(mtu) do
m:Destroy()
end
local mio = mtl[c]:Clone() --mapsinorder -- yeah you get what i mean
mio.Parent = workspace.LoadedMaps
if c == #mtl then
c = 1 -- jump back to the first child if it reached the folder length
else
c = c +1 -- otherwise add 1 to replace the first with 2nd-3rd etc etc
end
end)
any help?
Because if I make a table of the folder that means I have to make a new line
to add another map in the MapsToLoad if I make a new map in the future so it will
take up alot of lines.
Hey, I just wrote up something that could help you.
This code should sort a table in alphabetical order (A - Z) from left to right. If it’s not what you’re looking for, let me know. I also wrote out of my own curiousity, as I like trying new things in programming. So, sorry if it’s horribly inefficient haha, I haven’t studied sorting algorithms quite yet lol.
Here it is:
local myTable = {"Hello", "Add", "Substract"}
local activated = true
while activated == true do
for i = 1, #myTable, 1 do
if myTable[i] and myTable[i - 1] then
if string.byte(myTable[i]) >= 65 and string.byte(myTable[i]) <= 90 then
if string.byte(myTable[i]) < string.byte(myTable[i - 1]) then
local previous = myTable[i - 1]
local current = myTable[i]
myTable[i] = previous
myTable[i - 1] = current
activated = true
else
activated = false
end
end
end
end
end
EDIT: This will only work if,
The elements in the array are strings
The first character in each string is a letters A - Z or a - z (not symbols and such)
Just a note, it isn’t bug proof or anything, so feel free to improve however you need
local SS = game:GetService("ServerStorage")
local mtl = SS.CustomMaps:GetChildren() --mapstoload
local c = 1
script.Parent.RegenControl.Signal.Changed:Connect(function()
wait(5)
local mtu = workspace.LoadedMaps:GetChildren() --mapstounload
for _, m in pairs(mtu) do
m:Destroy()
end
for _, mapstoloop in pairs(mtl) do
local mio = mapstoloop[c]:Clone()
mio.Parent = workspace.LoadedMaps -- here, should it work?
end
if c == #mtl then
c = 1
else
c = c +1
end
end)
local abc = "abcdefghijklmnopqrstuvwxyz"
local Index = 1
while true do
local Found = false
repeat
if Index > 26 then Index = 1 end
local char = abc:substr(Index, Index)
for i,v in pairs(game.ServerStorage.CustomMaps:GetChildren()) do
if v.Name:lower():substr(3,3) == char then
-- Unload Old Map
-- Load Map
Found = true
end
Index += 1
break
end
until
Found = true
wait(180)
end
You could try something like this…
I havent tested it or anything