Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I chose a random object in a folder and clone it to workspace?

I need a script that accesses a folder in the ServerStorage and randomly chooses one item in that folder and then clones it into the workspace.

The folder is named Choices, so it would be "game.ServerStorage.Choices"

There are 10 objects in the folder all named 1-10

The following script doesn't work...

wait(5)
local chosen = math.random(1,10) --Chooses a random # 1-10
print(chosen) --Prints random # chosen
game.ServerStorage.Choices(chosen):Clone().parent = game.Workspace --is supposed to access a folder named, "Choices" located in the ServerStorage then get the random # and clone it into workspace...

1 answer

✓ Accepted answer

The way you wrote the array is incorrect. Use brackets instead:

game.ServerStorage.Choices[chosen]:Clone().parent = game.Workspace

2 comments

0

Yes it worked! Thanks

0

No problem.

This discussion is preserved as it was. New answers, comments, and votes are closed.