So, I'm needing a question answered.. and like, I want to know how to use math.random to get object names in a certain folder for a minigame script I'm doing. Couldn't figure it out. So, If anyone is kind enough please help me out - this is not a request though.
How to use math.random in a way to get a name out of a folder?
2 answers
This is actually pretty simple. All you would have to do is get the children of the folder and then set up math.random to select an entry of the table :GetChildren returns. For my example, my folder will have 5 entries.
local gameFolder = game:GetService("ReplicatedStorage").gameFolder
local games = gameFolder:GetChildren()
local function chooseGame()
local num = math.random(1,5)
local chosenGame = games[num]
return chosenGame.Name
end
local nextGame = chooseGame()
print(nextGame)
5 comments
you can use math.random(1,#games) so you don't have to change the script in the future
Thanks for the script, never wanted one in the first place - just an explanation on how to make one. either way, thank you.
No problem :)
Also, thanks Dfzoz I didn't think of that
Txeer Your not allowed to assist with asking questions. ITS AGAINST THE COMMUNITY GUILDLINES. https://scriptinghelpers.org/help/community-guidelines
This aint a asking website, Try looking it up please. Thank you! We cannot assist you as its against the Community Guildlines
1 comment
I did try looking it up.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Post an attempt, what you have currently, or know you might need for this.