Hi I was making a table with the rounds and I came across an error of when i said if the round was equal to the same round that was chosen then it would play that game. But it just kept picking one round. Can you help?
local round = rounds[math.random(1,#rounds)] getfenv()[round]() h.Text = "Starting the game..." wait(5) for _, player in pairs(game.Players:GetPlayers()) do if player.Character then player.Character:MoveTo( gamespawns[math.random(#gamespawns)] ) end wait(1) -- EDIT end if round == "Teamwork" then end if round == "Color Cows" then end if round == "Exploding Cows" then end if round == "Classic" then for time = 300, 1, -1 do workspace.GameMusic.Sound:Play() wait(1) h.Text = time .. " seconds left" if getWinner() then workspace.GameMusic.Sound:Stop() break -- ended the game early end end end
wasdwasdwafsa i got no idea on what to write here
Tables
is a variable of information, and is quite handy.
to index a table, you do:
table[1]--First index
Since you are math.random
ing gives a random number between a and b.
You are math.random
ing between 1 and the length of round
, which is a table
.
That'll return a random index in round
So that's how we choose a random index!
So, now how to activate that?
What if we use another table
?
We can store the functions in a table, with Keys
, that'll make this table a dictionary.
local roundFunc = { Classic = function() --code end, ["Colorful Cows"] = function() --code end, ["Exploding Cows"] = function() --code end }
Since this is a Dictionary
, we won't be able to index the normal way, using intergers.
Instead, we can use Strings
to index.
local roundFunc = { Classic = function() --code end, ["Colorful Cows"] = function() --code end, ["Exploding Cows"] = function() --code end } local modes = {"Classic","Colorful Cows", "Exploding Cows"} local randomMode = modes[math.random(1,#modes)] roundFunc[randomMode]()--Indexing using a string.
BAM AND THERE YOU GO!