Help with random placement of objects

I set up a script that randomly places trees around the map, but I’m getting weird “lines” of them appearing.

Right now it’s just using math.random() to place these trees. Is there a better way to space these trees out randomly so they’re more evenly scattered?

1 Like

Can you give us some code of the tree placement script where the Pivot or CFrame is set?

1 Like
local function Place(Tree,i)
	local PreviousPosition = Vector3.new(-233.008, 93.614, -155.379)
	while i > 0 do
		while true do
			local Clone = Tree:Clone()
			local Start = Vector3.new(math.random(-1050,865),400,math.random(-636,738))
			local Direction = Vector3.new(0,-500,0)

			local Raycast = workspace:Raycast(Start,Direction)
			print(Raycast)
			if Raycast then
				if Raycast.Instance:IsA("Terrain") and Raycast.Material == Enum.Material.Grass and (Raycast.Position-PreviousPosition).Magnitude > 30 then
					Clone.Parent = workspace.WorkspaceTrees
					Clone:PivotTo(CFrame.new(Raycast.Position))
					PreviousPosition = Raycast.Position
					break
				end
			end
			wait()
		end
		i-=1
	end
end

i is 65 and 60 for the 2 different trees