Hello, I have a problem where module scripts randomly are and are not being required. Here is the explanation:
Theres a big folder full of instances, and I’m trying to decide which random one to choose based off if they pass the unique conditions that they have.
I do this through having each child contain a module script that does this:
print("Required")
return(1+1==2 and 5+5==10) -- just an example, but returns true or false depending
Then in a different script, I get a random child and check to see if the conditions are passed, if not then continue to choose a random child:
-- this is also a module script btw
return function()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Decisions = ReplicatedStorage.Decisions
local Decision = nil
local i = 0
repeat
i += 1
print(i) -- prints every time it tries a new child
local Chosen = Decisions:GetChildren()[math.random(1, #Decisions:GetChildren())]
local Choice = require(Chosen.Conditions)
if Choice == true then
Decision = Chosen
end
until Decision ~= nil
print("Found!")
return Decision
end
It’s meant to print something like this as for each time it checks the condition it is requiring the module inside of the child:
1
Required
2
Required
3
Required
Found!
But instead it prints something random like this:
1
2
Required
3
-- note how its not saying its required even when it says its found
Found!
It would be in a random pattern like that, randomly saying it’s required and randomly not, then saying it was found without ever requiring it.
I have no clue why this could be happening unless it’s something to do with Roblox, because there’s no pattern in it, just random.
Any help or closure would be greatly appreciated. Many thanks.