✓ Accepted answer
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.
2 comments
Select a random number from 1 to (how much wheat you have): x = math.random(1, #wheat). The amount of wheat you lose is that number subtracted by the total amount of wheat. y = #wheat - x.
To get rid of random wheat, make a loop that runs y times to index a random position of a table with all the wheat (if they're all grouped, GetChildren will do) and use the Destroy function in the object of that position of the table.