Script not getting the random position in the right way


as shown on the picture when the part is getting rotated the objects that are getting spread inside of it aren’t placed the right way.

	for i = 1, quantity do
		local newIngredientObject = ingredientObject:Clone()
		newIngredientObject.Parent = ingredientsFillPart
		newIngredientObject.CFrame = CFrame.new(gameFunctions.getRandomPositionInPart(foodStand:WaitForChild("IngredientsFillPart"))) * CFrame.Angles(math.rad(math.random(-45, 45)), math.rad(math.random(-45, 45)), math.rad(math.random(-45, 45)))
		newIngredientObject.Anchored = true
	end

function that gets random position:

function GameFunctions.getRandomPositionInPart(part)
	local x = part.Position.X + math.random((-part.Size.X/2)*100,(part.Size.X/2)*100)/100
	local y = part.Position.Y + math.random((-part.Size.Y/2)*100,(part.Size.Y/2)*100)/100
	local z = part.Position.Z + math.random((-part.Size.Z/2)*100,(part.Size.Z/2)*100)/100

	return Vector3.new(x, y, z)
end
1 Like