Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you make scripts execute in random order?

I'm trying to make scripts execute in random order, kinda like horrific housing, sorry if this is a request it was my last choice.

2 answers

✓ Accepted answer

a way you could do this is by having one central script, with a math.random function. like this:

while wait(10) do -- any number works
local number = math.random(1,10)
if number == 1 then
print("doing things")
elseif number == 2 then
print("doing more things")
--and so on
end

Use a ModuleScript. You can read more about them here.

Basically, make one parented to your regular script. then do something like:

local modes = {}

function modes:Mode1()
	--Code for mode 1
end)
function modes:Mode2()
	--Code for mode 2
end)
function modes:Mode3()
	--Code for mode 3
end)

--Repeat

return modes

Then, in your regular server, do something along the lines of:

local modeModule = require(script:WaitForChild("The name of your module script here"))

while true do
	mode = math.random(1, the number of modes you have)
	if mode == 1 then
		modeModule:Mode1()
	elseif mode == 2 then
		modeModule:Mode2()
	elseif mode == 3 then
		modeModule:Mode3()
	end
end

Hope this helps. Also I didn't test this, reply with errors!

This discussion is preserved as it was. New answers, comments, and votes are closed.