generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Random selection

Previous Thread :: Next Thread 
Aluporesm is not online. Aluporesm
Joined: 08 Oct 2016
Total Posts: 9
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
Aluporesm is not online. Aluporesm
Joined: 08 Oct 2016
Total Posts: 9
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
TehIcyStar is not online. TehIcyStar
Joined: 07 Mar 2010
Total Posts: 1649
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
Aluporesm is not online. Aluporesm
Joined: 08 Oct 2016
Total Posts: 9
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image