Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to clone parts with random Orientation and Position without cloning multiple?

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.

2 comments

0

Is the reroll function for a button? Is it a client script or a server script? Can you show the whole script for referrence?

0

The reroll function just automatically begins when i press the start button. It is a server script that is a child of the reference leaf i am cloning.

1 answer

✓ Accepted answer

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.

1 comment

0

thank you :)))

This discussion is preserved as it was. New answers, comments, and votes are closed.