This is what is happening and this shouldnt be happening because the raycasting is only accepting terrain
Here is the code i have so far
local zonePlus = require(game.ReplicatedStorage.Modules.Zone)
local zone = zonePlus.new(workspace.GenerateZone)
local rcParams = RaycastParams.new()
rcParams.FilterDescendantsInstances = {
workspace.Terrain
}
rcParams.FilterType = Enum.RaycastFilterType.Whitelist
for i = 1,workspace.GENERATION_SETTING.Trees.Value do
local randomVector,touchingzonepartsarray = zone:getRandomPoint()
local tree:Model = game.ReplicatedStorage.Misc.Tree:Clone()
local treeSize = tree:GetExtentsSize()
tree.Parent = workspace.Trees
tree:MoveTo(randomVector)
local rc = workspace:Raycast(tree.PrimaryPart.Position,Vector3.new(0,-10000,0),rcParams)
if rc then
print(rc.Instance)
tree:MoveTo(rc.Position + Vector3.new(0,treeSize.Y/2,0))
else
tree:Destroy()
end
end
^ This functions sets a models position, but if there are any obstructions where the model is to be moved to, such as Terrain or other BasePart s, then the model will be moved up in the Y direction until there is nothing in the way. If this behavior is not desired, [Model:SetPrimaryPartCFrame()](Model:SetPrimaryPartCFrame) should be used instead.
source: Model:MoveTo
You have to set the Primary Part of the Tree and adjust the position based on the ray to it. Make sure to also translate it into CFrame to use Tree:SetPrimaryPartCFrame()