Hello, Im trying to make a script randomly pick a part from within a folder of parts. The parts name begins the same however the number at the end varies. I need it to pick the correct part and then randomly pick one of these numbers. If that makes sense…
For example, The parts in the folder are Gun1, Gun2, Gun3 etc among other parts.
I need to be able to ensure the part picked is called Gun and then randomly pick one of these guns?
local Folder = YourFolder
local Children = YourFolder:GetChildren()
local function GetRandom()
local Num = math.random(1, #Children)
local Item = Num:Clone(); Item.Parent = YourLocation
end
Thankyou for your quick response, How would this be implemented?
As for my example above I don’t understand how this would check if one of the children are called Gun and if there are multiple results how it would then randomly pick one of them?
To put it simply, GetChildren gets all Children within your Folder and Turns it into a Table,
The math.random gets a Random Item within the Table,
Since the Items inside the Table are Model, Tools, etc, They will be able to be cloned
Example:
Numbers = { -- Misleading Table
[1] = "Hi", -- First Item in the Table
[2] = "Hello",
[3] = "Hey"
}
print(Numbers[1]) -- Prints the First Item in the Table
print(#Numbers) -- Prints the Number of Items in the Table
print(Numbers[math.random(1, #Numbers)]) -- Prints a Random Item in the Table