In my game, you stack moving blocks and any overhang from the previous block should be cut and unanchored. I achieve this by creating two separate blocks upon placement: one part for the side to be unanchored and one for the part that stays on.
The issue though is that when there is a significant overhang quite early on, this happens:
The part that’s meant to stay on doesn’t change size or position.
This has caused tons of confusion as when I print the size, it says that the size of the block is what it was meant to be even though that’s not what’s being displayed. Even more confusing, I send the properties of the block to the server through a RemoteEvent (Size, Position, Color) so it can be displayed to everyone else, and when I do in this case, it shows as intended:
This issue doesn’t happen when the overhang is not as much.
I’ve tried re-writes and stuff, and also tried to find relevant Dev Forum posts but I still can’t figure out this issue, the code is here:
--script that occurs when block is placed
local function distance(num1,num2)
local dist = num1-num2
if dist<0 then dist = dist*-1 end
return dist
end
local style = ""
local MovingFarOne = Vector3.new(stack.MovingPart.Position.X+(stack.MovingPart.Size.X/2),stack.MovingPart.Position.Y,stack.MovingPart.Position.Z) --Gets the position of the left-most X side of the moving block
local MovingFarTwo = Vector3.new(stack.MovingPart.Position.X-(stack.MovingPart.Size.X/2),stack.MovingPart.Position.Y,stack.MovingPart.Position.Z) --Gets the position of the right-most X side of the moving block
local NewFarOne = Vector3.new(stack.NewestPart.Position.X+(stack.NewestPart.Size.X/2),stack.NewestPart.Position.Y,stack.NewestPart.Position.Z) --Gets the position of the left-most X side of the previous block
local NewFarTwo = Vector3.new(stack.NewestPart.Position.X-(stack.NewestPart.Size.X/2),stack.NewestPart.Position.Y,stack.NewestPart.Position.Z) --Gets the position of the right-most X side of the previous block
if MovingFarOne.X>NewFarOne.X and MovingFarTwo.X<NewFarOne.X then
style = "CutOne" --Overhang at the left side
elseif MovingFarTwo.X<NewFarTwo.X and MovingFarOne.X>NewFarTwo.X then
style = "CutTwo" --Overhang at the right side
elseif stack.MovingPart.Position.X == stack.NewestPart.Position.X then
style = "Perfect" --No overhang
else
style = "GameOver"
end
if style == "CutOne" then --The issue applies to all "styles"
local lengthofoverhang = distance(MovingFarOne.X,NewFarOne.X) --gets distance of overhang
local newblock = stack.MovingPart:Clone()
newblock.Parent = stack
newblock.Size -= Vector3.new(lengthofoverhang,0,0)
newblock.Position = Vector3.new(NewFarOne.X-(newblock.Size.X/2),newblock.Position.Y,newblock.Position.Z)
newblock.Name = "TempName"
newblock.Slam:Play()
local stackoverhang = stack.MovingPart
stackoverhang.Name = "deb"
stackoverhang.Parent = workspace.Debris
stackoverhang.Size = Vector3.new(lengthofoverhang,stackoverhang.Size.Y,stackoverhang.Size.Z)
stackoverhang.Position = Vector3.new(NewFarOne.X+(lengthofoverhang/2),newblock.Position.Y,newblock.Position.Z)
stackoverhang.CanCollide = false
stackoverhang.Anchored = false
newblock.Name = "MovingPart"
rs.Remotes.Stack.StackReceive:FireServer({newblock.Position,newblock.Color,newblock.Size}) --sends information
return
elseif --continues here
I do know the issue isn’t a result of the “style” being incorrect, nor the overhang not being unanchored. It just looks like the part’s size/position isn’t being displayed right?