I wish to place the forcefields in the correct archways and I used a simple print statement to check that the forcefields and archeways will be ordered properly but they aren’t. I’m pretty sure I need to use another arguement but I’m not sure what that is. Here is what’s printed.
---- Place the forcefields in the correct positions ----
local replicatedStorageService = game:GetService("ReplicatedStorage")
local forcefieldFolder = replicatedStorageService:WaitForChild("Forcefields")
local archwaysFolder = game.Workspace.GameAssets.Archways
for i, v in ipairs(forcefieldFolder:GetChildren()) do
if v:IsA("Part") then
print(i, v.Name)
end
end
for i, v in ipairs(archwaysFolder:GetChildren()) do
if v:IsA("MeshPart") then
print (i, v.Name)
end
end
Yeah I already read that one but I thought ipairs was supposed to order the parts but doesn’t seem to. If I can’t make option 1 work then I’ll go with option 2.
local array = {"b","c","a"}
for i,v in ipairs(array) do
print("Index:", i, "Value:", v)
end
--[[ the output is in order
Index: 1 Value: b
Index: 2 Value: c
Index: 3 Value: a
]]--
You’re using :GetChildren() to get the instances, which doesn’t sort the returned array in alphanumeric order.
If you wanted to sort them, you’d have to run your own sort operation.
Yeah that’s obviously true but I’m not really sure how to do that. “part1” matched with “meshpart1” etc so when I clone the parts from the replicated storage I know that the parts will be in the correct place. This is because the forcefield1-5 cost different amounts to turn off and I want them to be placed from cheapest to most expensive.