I am making a game where you pick up leaves that fall from trees and sell them for money. I made a script to Clone leaves with a random position (-15.5 to 15.5) with a random orientation, the orientation being in increments of 15:
function reroll() local leaf = script.Parent:Clone() leaf.Parent = game.Workspace.Leaves leaf.Position = Vector3.new(math.random(-15.5, 15.5), 1.75, math.random(-15.5, 15.5)) leaf.Orientation.Y = (math.random(1, 12) * 15) end reroll()
The script clones these leaves into a folder in workspace called Leaves, as seen here
local leaf = script.Parent:Clone() leaf.Parent = game.Workspace.Leaves
The problem is, when I put the "reroll" function at the end, it clones 3 in random positions instead of 1. It also clones a 4th, but that one remains with the same position and orientation as the reference leaf that I am cloning (the parent of the script). I want to clone just 1 leaf with correct orientation and position. Any help is appreciated. Thank you.
You are cloning script.Parent which means the script is also being cloned. You now have 4 Pieces because Roblox throws an Error after the third clone to prevent crashing.
Just put the script outside the Leaf.