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

How to use math.random in a way to get a name out of a folder? [closed]

Asked by 4 years ago

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.

0
Post an attempt, what you have currently, or know you might need for this. hiimgoodpack 2009 — 4y

Closed as Not Constructive by Ziffixture

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

2 answers

Log in to vote
1
Answered by
Txeer 46
4 years ago
Edited 4 years ago

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)
2
you can use math.random(1,#games) so you don't have to change the script in the future Dfzoz 489 — 4y
0
Thanks for the script, never wanted one in the first place - just an explanation on how to make one. either way, thank you. User#22722 20 — 4y
0
No problem :) Txeer 46 — 4y
0
Also, thanks Dfzoz I didn't think of that Txeer 46 — 4y
0
Txeer Your not allowed to assist with asking questions. ITS AGAINST THE COMMUNITY GUILDLINES. https://scriptinghelpers.org/help/community-guidelines Lakodex 711 — 4y
Ad
Log in to vote
-3
Answered by
Lakodex 711 Moderation Voter
4 years ago

This aint a asking website, Try looking it up please. Thank you! We cannot assist you as its against the Community Guildlines

0
I did try looking it up. User#22722 20 — 4y