I'm trying to make a script that chooses a model in replicated storage randomly and clone it to the workspace every 5 seconds. How would you do that? I'm not a very good scripter, and I'm still learning. Help?
How to ch0ose a model randomly and clone it to workspace?
1 answer
You can do this using the GetChildren function and the random function in the math library.
The GetChildren function returns a table of all the children parented to an object. We can use that to get all of the things in ReplicatedStorage. We can then use the random function to generate a number between 1 and the number of children we found, like so math.random(#children).
We can use this number as an index to retrieve a child from our table and clone it into the workspace.
local children = game.ReplicatedStorage:GetChildren()
while true do
index = math.random(#children)
children[index]:Clone().Parent = game.Workspace
wait(5)
end
Note that this grabs every child of ReplicatedStorage. So if you had something in there other than a model you wanted to clone, it could also be cloned into the workspace. You can fix this by parenting all the models you want to clone into a folder (or another model) and getting the children of that instead.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Thanks man!