So, I have a Module Script with a bunch of functions in it and what I want to do is calling a random function from this module
Module script:
local events = {}
events.GrowPlate = function(plate:BasePart)
print("Growing plate")
end
events.ShrinkPlate = function(plate:BasePart)
print("Shrinking plate")
end
return events
What I want to do is a while loop calling a random function from this table each time it loops
local ServerScriptService = game:GetService("ServerScriptService")
local Events = require(ServerScriptService.Modules.Events)
while wait(1) do
--I need to call the random function here
end
I have tried to do math random but it definitely wouldnt work. Even if its not a Module Script I dont think it would work at all
while wait(1) do
Events[math.random(#Events)]
end
This is the only solution I have tried so far, as I can’t think of any other way to do it, if anyone knows how I can do it I would appreciate any help.
While you can’t get the length of a dictionary, you can get the values of that dictionary. Try to fetch the functions of the module script into a different array, then loop that array instead. This may comes with some fallbacks, but this should be a way to iterate a dictionary’s values.