Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I randomize functions?

Asked by 5 years ago

I am trying to call the functions randomly. But I do not know where to start. Any tips on how to begin? I have tried using math.random but no success.

01local paper = game.ReplicatedStorage.Spawnables.Paper
02local folder = game.ReplicatedStorage.Spawnables
03 
04-- paper spawnings
05    function paperSpawn()
06    local spawnPaper = paper:Clone()
07    spawnPaper.Parent = workspace
08    local xpos = math.random(-100, 100)
09    local ypos = 0.5
10    local zpos = math.random(-100, 100)
11    spawnPaper.Position = Vector3.new(xpos, ypos, zpos)
12    end
13    function voidSpawn()
14    local spawnPaper = folder.VoidPaper:Clone()
15    spawnPaper.Parent = workspace
View all 69 lines...

1 answer

Log in to vote
1
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago

put all your functions into a table:

1myFunctions = {paperSpawn, voidSpawn, redPaper, LightPaper, GoldPaper,DiamondPaper,EmeraldPaper,PurplePaper}

and then use math.random() to get a random functionL

1randomFunction = myFunctions[math.random(1, #myFunctions)]
2 
3--calls random function
4randomFunction()
Ad

Answer this question