So how the script works is It looks for terrain with rays and all that good stuff, summons a part randomly on the terrain, and sets the properties. The problem is all 2000 parts generate, but the 2000 meshes only go to one part instead of all 2000 parts. My code here:
--Tree Gen, Codded by Kennqu
math.randomseed(tick()) --Will 'randomize' our pseudo-random num generator.
local check_height = 100 --Makes sure trees wont spawn Over the designated Y axis pos.
local map_x, map_y = 4000, 4000 --Define map size.
local Num = 2000 --How many trees to be spawned.
--Now, lets use a loop to set how many trees will be placed.
for i = 1, Num do
local rand_x = math.random()*map_x
local rand_y = math.random()*map_y
local ray = Ray.new(
Vector3.new(rand_x, check_height, rand_y),
Vector3.new(0, -1, 0)*300
)
local inst, position = workspace:FindPartOnRay(ray, nil, false, true)
if inst and inst:IsA("Terrain") then
--(rand_x, position.y, rand_y)
local NewTree = Instance.new("Part", workspace)
NewTree.Position = Vector3.new(rand_x, position.y, rand_y)
NewTree.Anchored = true
NewTree.CanCollide = false
NewTree.Transparency = 0.012
NewTree.Name = ("TreeG")
end
end
for i = 1, Num do --Gives the empty 'Invisible' parts a mesh to make it a tree.
function GiveMesh()
local NewTreeBody = Instance.new("SpecialMesh", workspace.TreeG)
NewTreeBody.MeshId = ("rbxassetid://2640968479")
NewTreeBody.TextureId = ("rbxassetid://2640968592")
NewTreeBody.Offset = Vector3.new(0, 36, 0)
NewTreeBody.Scale = Vector3.new(4, 8, 4)
end
GiveMesh()
end

5 comments
Think you kind sir!
np pls ask questions if you have any questions
he still hasnt accepted the answer yet
Answer has been accepted.
ty bruv <3