Greetings,
I and my friend made a wheat farm, and we wanted to make a script that makes it select a random number of wheat and make it disappear (like a 30% shows and the rest is gone). How would I start doing it? Maybe using math? Or other parameters? Any answer is helpful.
I tested it out and it works used ClickDetector to fire my script.
script.Parent.ClickDetector.MouseClick:Connect(function() local child = game.workspace.Folder:GetChildren() local x = 30/100*#child local y = math.ceil(x) print(y) for i = 1,y do child[i]:Destroy() end end)
So I rounded down the value of x
which is 30% of the entire wheat.
I parented the wheat to a Folder which then I used :GetChildren()
to retrieve all the wheat. I then used the operator '#' to get the count of the amount of wheat. So 30/100*#child. Which then I rounded it up to prevent decimals.
A bit of math.random magic would do the trick
local ModelThing = workspace.Model:GetChildren for i = 0,math.random(1,#ModelThing),1 do -- loop for a random amount of times depending on how many children are in the model ModelThing[i].Transparency = 1 -- index the table from getchildren and change the transparency to 1 end
I'm not 100% sure this will work so let me know if you have issues with it!