I have a system to randomize room settings with a random seed. I did this because if the random system generated something impossible, i can reproduce it. The bug is that it is impossible to get a median number. Here is the code:
local traverseseed = Random.new():NextInteger(1,50)
local traverseindict = Instance.new("IntValue")
traverseindict.Name = "seed"
traverseindict.Value = traverseseed
traverseindict.Parent = traverseroom
for _,item:Model in pairs(chapter.traverseCritItems[traverseroom.Name]:GetChildren()) do
local takenspawns = {}
local previousindex = 0
local itemspawn = nil
local index = 1
for count = 1,traverseseed,1 do
index = math.clamp(count,1,#chapdata.traverseCRITITEMspawns[traverseroom.Name])
print("indexs: "..index.." "..previousindex.." "..#chapdata.traverseCRITITEMspawns[traverseroom.Name].." ".."origcount: "..count)
task.wait()
if index > #chapdata.traverseCRITITEMspawns[traverseroom.Name] or previousindex == #chapdata.traverseCRITITEMspawns[traverseroom.Name] then
print("reseting index")
previousindex = 0
index = 1
print("resetted indexs: "..index.." "..previousindex.." "..#chapdata.traverseCRITITEMspawns[traverseroom.Name].." ".."origcount: "..count)
end
previousindex = index
if not table.find(takenspawns,chapdata.traverseCRITITEMspawns[traverseroom.Name][index]) then
itemspawn = chapdata.traverseCRITITEMspawns[traverseroom.Name][index]
table.insert(takenspawns,itemspawn)
else
local failed = false
local attempts = 10
repeat
attempts -= 1
index += 1
until not table.find(takenspawns,chapdata.traverseCRITITEMspawns[traverseroom.Name][index]) or attempts == 0
if attempts == 0 then
warn("Not enough spawns for all items, deleting")
item:Destroy()
end
end
task.wait()
end
item:PivotTo(itemspawn)
item.Parent = traverseroom
end
Thanks for any help!
(if you want to test a early access build of the game, dm me. dont flag this post pls lol)