Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 2 years ago

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.

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? T3_MasterGamer 2189 — 2y
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. Robax_PLAYA 14 — 2y

1 answer

Log in to vote
0
Answered by
xXMadonXx 190
2 years ago

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.

0
thank you :))) Robax_PLAYA 14 — 2y
Ad

Answer this question