--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:
This is only for the Y value- the X and Z values are positioned fine. When running this on virtually the same thing in a different testing environment, it works perfectly. There is only one difference- in the game, the sizing of the land piece is random, and I tween the land piece into position. I’m starting to believe this could be part of the problem. Here’s the code:
--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 the variables I left undefined (since these come from two separate parts in the script, I didn’t want to show all that since it’s unnecessary) are quite self-explanatory, but if you have any questions, I’ll try to answer them.