So I made a script that spawns trees randomly around a specific area, but every so often a tree will spawn on top of another. So when a tree spawns I want to check if it's position is higher than a specific value. I'm not sure how to do this but if somebody could help me it would be a big help. Thanks!
COMMUNITY QUESTION
How do I check if a parts y position is higher than a specific value?
1 answer
You could use GetPrimaryPartCFrame to get the CFrame of the tree. This can only be called after the PrimaryPart is set.
local Y_NUMBER = 5
if Tree:GetPrimaryPartCFrame().Y > Y_NUMBER then
-- ok
end
Although this is the answer to your question, I would also want to make sure trees aren't spawning inside of each other or near each other. A simple fix to this would be to check the distance between the tree being spawned and every other tree to make sure they aren't too close.
This discussion is preserved as it was. New answers, comments, and votes are closed.
