--position "nature"'s y coordinate
local structureItem = structure:Clone()
local position = structureItem:GetPivot()
local landPos = land.CFrame * CFrame.new(0, land.Size.Y / 2, 0)
local size = structureItem:GetExtentsSize()
local yValue = size.Y/2
structureItem.WorldPivot = CFrame.new(structureItem.WorldPivot.X, yValue, structureItem.WorldPivot.Z)
structureItem:PivotTo(landPos * CFrame.new(0, yValue, 0))
This isn’t the entire code, but it’s the code that affects the Y value of the generated structures. As far as I can tell, this should be where the issue lies, as everything else seems to be working perfectly- however, if you ask for more, I’ll reply to you with the full code.
The point of the code is to position the generated structure’s Y value so it is directly on top of the land it is being built on.
Instead, I get this:
local landPos = land.CFrame * CFrame.new(0, land.Size.Y / 2, 0)
This one line is the exact position at the top of the structure. But then when you PivotTo the structureItem to the landPos, you add the yValue on top which places it a bit higher.
What would happen if you just wrote structureItem:PivotTo(landPos) in place of that last line?
--position "nature"'s x and z coordinates based off of offset parameter
local newPosition = natureItem:GetPivot()
natureItem:PivotTo(newPosition * offSet)
I don’t think this matters, but just in case, here’s the positioning of the x and z coordinates that comes shortly afterwards.
The offSet can be (-16, 0, 16), (-16, 0, 16), (16, 0, -16), or (16, 0, 16).
Yeah, I tested this in the same environment- same sized land piece, same models I’m using here- and it worked perfectly. There is one difference though, and that’s that the land piece is being tweened into it’s position. This shouldn’t matter though, because all parts of the script handling structure generation occur after the tween is completed.
So, I don’t think the problem is with the structure- however, it could be with the land…? If you want, try randomizing the size of the part and tweening it around before positioning the new part on top of it.
Remember, this problem is exclusive to the Y value, the X and Z values work fine.
Here’s the code handling the sizing and tweening of the land:
--resizing garbage
newLand.Size = newLand.Size + Vector3.new(0, heightDifference, 0)
local magnitude = (newLand.Position.Y - game.Workspace.Baseplate.Position.Y)
newLand.Size = newLand.Size + Vector3.new(0, magnitude, 0)
local goal = {Position = newLand.Position} -----------------------------------------helpful for tweening later
newLand.Position = newLand.Position - Vector3.new(0,50,0)
--tweening land for ground emergence animation
local tweenInf = TweenInfo.new(5)
game.ReplicatedStorage.screenShake:FireAllClients()
landBuildSound:Play()
local tween = tweenServ:Create(newLand, tweenInf, goal)
tween:Play()
tween.Completed:Wait()
landBuildSound:Destroy()
I believe most of the variables left undefined are relatively self-explanatory, but if you need context just ask.