|
| 23 Oct 2016 08:31 PM |
I'm trying to make an script which picks a random part and clones it To prevent the random part choosed being cloned again we put the part in a table When the table is full (All parts already cloned), i clean the table so we can start again.
Sorry if i don't know how to explain but here's my script that i've done. I hope it explains itself better than i did :'P
local partsToClone = workspace:WaitForChild("Parts"):GetChildren() local alreadyCloned = {}
local cloneFolder = workspace:WaitForChild("Clone")
--Just a 2 seconds loop for example. while wait(2) do --If the table isn't full we can continue if #alreadyCloned < #partsToClone then --Another loop that picks the random part and make sure it wasn't already cloned while true do local randomPart = partsToClone[math.random(1, #partsToClone)] if not alreadyCloned[randomPart] then print(randomPart) local randomPartClone = randomPart:Clone() randomPartClone.Parent = cloneFolder --Here we insert the random part in a table to prevent it being cloned again table.insert(alreadyCloned, randomPart) break end wait() end else --Otherwise we clean it and we start again print("---------------") alreadyCloned = {} end end
My question is: why when i pick a random part and put it in a table to prevent it being cloned again, it's being cloned again? Where's my mistake?
I hope you can help me Thanks for reading |
|
|
| Report Abuse |
|
|
|
| 23 Oct 2016 08:33 PM |
| Oh, i forgot to mention that i don't speak english, So that's why i don't know how to explain better. D: |
|
|
| Report Abuse |
|
|
|
| 23 Oct 2016 08:36 PM |
Instead of making a banlist, why not make a whitelist?
it's going to be much easier.
local PartsThatCanBeCloned = ClonableParts:GetChildren() local tenRandomParts = {}
for i=1,10 do ChosenPart = math.random(1,#PartsThatCanBeCloned) --choose part number tenRandomParts[i] = PartsThatCanBeCloned[ChosenPart] --do a thing with the chosen part table.remove(PartsThatCanBeCloned,ChosenPart) --remove the part from the table end
look how short this was! |
|
|
| Report Abuse |
|
|
|
| 23 Oct 2016 09:27 PM |
Thanks for helping me! Was more easy than i expected :P And sorry for my bad Scripting Skills. I have much more to learn cx |
|
|
| Report Abuse |
|
|