Block CFrame issues

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I am making a game where you can save blocks you have placed (as long as there in the building zone).

  1. What is the issue? Include screenshots / videos if possible!
    however, when you save the blocks it saves the cframe of the block in world space, meaning if the building zone is moved, it will still be in the same position as you saved it.

  2. What solutions have you tried so far? Did you look for solutions on the Creator Hub?
    I have tried to use ToObjectSpace() but am still confused, here is an example.

-- blockCFrame:ToObjectSpace(buildingZone.CFrame)

i need to save the blockCFrame relative to the building zone and load the blocks in a cframe relative to the building zone (for example, if i save a block is 2 studs from the center of the building zone and then i move the building zone 2 studs, the block should load 2 studs from the center of the building zone which is now 2 studs off).

what should i do?

When saving, just subtract the building zone’s position/cframe from the block’s cframe:

const SavedCFrame = Block.CFrame - Zone.Position

That’ll give you the offset of the block, which can then be used on a different zone when you load it again:

Block.CFrame = SavedCFrame + NewZone.Position

If each zone is rotated differently, this will not work as intended; so if that’s the case lmk and I’ll help you with that (I’m on my phone rn, it’s hard to type out the whole thing)

To do that you need to use ToWorldSpace and ToObjectSpace


To get the relative CFrame:

local blockRelativeCFrame = buildingZone.CFrame:ToObjectSpace(block.CFrame)

And to get the global CFrame relative to another building zone:

local newWorldCFrame = newBuildingZone.CFrame:ToWorldSpace(blockRelativeCFrame)

this one ^
But they do not suggest saving CFrames because values lose precision after several load/save cycles, and, as a result, stuff drifts a little.
It’s better to use integers for this, something like, “slot number” and get actual value in run-time.

Add to world space that refers to the building zone this way it loads its previous relative position captured when saving. I’m also assuming your building zones are somewhat identical, thus you could do something like

saved =buildingzone.cframe:toobjectspace(block.cframe)
Block.Cframe = buildingzone.cframe:toworldspace(saved)