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

How do I make a random part chooser and cloner?

Asked by
iiSL_K 5
5 years ago

What I am trying to do is have a script in the ServerScriptService choose a random part from a folder called "perks" in the ServerStorage that contains parts. I would like the script to choose a random part and clone it to the Workspace but everything I have tried so far has not worked. If possible, can anyone help me with this script?

1 answer

Log in to vote
0
Answered by 5 years ago

Try this:

folder = game.ServerStorage
function ClonePart()
    parts = folder:GetChildren() -- Get parts
    if #parts < 1 then return end -- Make sure parts are in the folder
    part = parts[math.random(1, #parts)]
    newpart = part:Clone()
    newpart.Parent = workspace
end
ClonePart() -- Use this to clone once
-- OR --
while wait(5) do ClonePart() end -- Clone every 5 seconds
Ad

Answer this question