Loading a Model's CFrame at the right Baseplate

This is my first post on the Developer Forums, hopefully I explain it well enough for you.

What is the best method for adjusting a CFrame so it loads at the right point.

This example will help you understand what I’m trying to accomplish.

John joins my game and the server places him on base one.
He places 5 items on his base and leaves the game with his data saved.

John decides to join my game again the next day and the server places him on base four.
All his items load in, but their CFrames cause them to be positioned at base one.

You should save the position relative to the base instead of relative to the world origin.

For example, if each base is a model with a PrimaryPart set in a consistent way, then you could write:

local cframeToSave = baseModel.PrimaryPart.CFrame:Inverse() * itemObject.CFrame
-- later, after retrieving from data store
local cframeToSet = baseModel.PrimaryPart.CFrame * cframeFromDataStore

Edit: My original code was incorrect because I had the left and right sides of the multiply flipped around. It should work now.

8 Likes

I’ll experiment with it and tell you the results.

You can save its CFrame, put it in a model with a PrimaryPart, then position it like normal. When done use SetPrimaryPartCFrame() to move it to the right spot.

try

local X = Base.PrimaryPart.CFrame.X - Item.PrimaryPart.CFrame.X
local Z = Base.PrimaryPart.CFrame.Z - Item.PrimaryPart.CFrame.Z

local ItemData = {ItemName,X,Z}

then when loading just add the base cframe

It seems to work in Solo but not in regular game with more than one player (2-4). There are no errors, everything gets replicated, but the CFrame is wrong.

Using @Tiffblocks method because it looks cleaner. (Accidentally replied to myself, was trying to reply to you.)

This saves the model’s CFrame

local MediumTable = {}
MediumTable.ID = v.ItemConfiguration.ItemId.Value
MediumTable.Position = {(v.PrimaryPart.CFrame * Base.PrimaryPart.CFrame:Inverse()):components()}

This loads the model in.

local items = TheItem:Clone()
items:SetPrimaryPartCFrame(CFrame.new(unpack(v.Position))*CFrame.new(Base.PrimaryPart.CFrame:components()))
items.Parent = Base.ItemHolder

v.Position is the :component() data of the CFrame that I saved.

1 Like

Just to clarify, are you referring to legacy play solo? Or the new play solo (APS)?

(I presume legacy but it’s worth confirming)

I haven’t switched to the new play solo.
How do you do it?

See here for details including instructions on how to switch:

1 Like

2 year later…

I had that same problem and your answer actually helped me to find the answer.
small example:

When saving: X = Plot.CFrame.X - v.PrimaryPart.CFrame.X

When Loading: Plot.CFrame.X + -v.ObjectCFrame.X

1 Like