I have a script that loops through spawnable pads and inserts them into a table. I then try to random sort the table but it’s giving me 3 2 major issues.
Here’s the code in question:
local RNG = Random.new()
local function getSpawnPads(group)
local spawnPads = {}
for _, spawnPad in ipairs(group.SpawnPads:GetChildren()) do
if spawnPad:IsA("BasePart") then
if not spawnPad:FindFirstChildOfClass("Decal") then
table.insert(spawnPads, spawnPad)
end
end
end
table.sort(spawnPads, function()
return RNG:NextNumber() < 0.5
end)
print("Successful sorting. Results:")
print(spawnPads)
return spawnPads
end
I don’t even know what’s causing this.
I’ve tried printing spawnPads
pre-sorted and I don’t see anything wrong with it.
But it gets weirder. Sometimes, the sorting works, successfully spawning the first dummy. When it attempts it again, it will throw the same “invalid sorting function for sorting” error.
The table in the output is what the successful sorted table looks (works fine) before attempting again and erroring.
Note that these screenshots were from back to back play tests, no modified code. I’ve been at this for an hour now, I am very confused on what is causing this issue. I would appreciate any help!
Edit: Upon further testing, it seems that the code will throw an error if the function returns true