Datastoring a Plot

How are you saving item and position data?

And what does your code look like? We can tell you why it’s not working if we don’t even know how you’re doing it.

I deleted it due to my stupidity, I’m rewriting it now but it’s not going so well.

for i,v in pairs(TycoonValue.Value.Bin:GetChildren()) do
		local XPos = TycoonValue.Value.TycoonBaseplate.CFrame:inverse().X * v:GetPrimaryPartCFrame().X
		local YPos = TycoonValue.Value.TycoonBaseplate.CFrame:inverse().Y * v:GetPrimaryPartCFrame().Y
		local ZPos = TycoonValue.Value.TycoonBaseplate.CFrame:inverse().Z * v:GetPrimaryPartCFrame().Z
		ServerData[plr].TycoonPlacements[v.Name.."-"..i] = {
			['X'] = XPos;
			['Y'] = YPos;
			['Z'] = ZPos;
		} --TycoonValue.Value.TycoonBaseplate.CFrame:inverse() * v:GetPrimaryPartCFrame()
	end

This is saving the plot items, I haven’t wrote the loading yet.

1 Like

For my sandbox game which has really good/efficient saving, I use the CFrame methods: toWorldSpace and toObjectSpace

1 Like

First of all, good luck with your project!

If you have a primary part for all placeables, you can get those placeables’ primary part position by a basic CFrame formula. If I remember it right, it should be
Plot.CFrame:inverse() * Object.PrimaryPart.CFrame
and it basically subtracts plot CFrame from object PP CFrame. You also can use xuefei’s suggested methods.

Saving every placeable to a folder will give you chance to form a table easily. Like…

local SavingTable = {}
for i,v in pairs(Placed:GetChildren()) do
    local SavingCF = Plot.CFrame:inverse() * v.PrimaryPart.CFrame
    table.insert(SavingTable, {SavingCF, ItemID, ...})
end

Finally, use JsonEncode to turn SavingTable into a string as iRexBot suggested because you can’t save MetaTables(Tables inside tables).

3 Likes

Having the exact same issue with my sandbox tycoon, any help will be greatly appreciated.

This might be of use: Loading a Model's CFrame at the right Baseplate

1 Like

I did the method you said (which was brilliant by the way), I’m not sure why this is happening.

The console outputs that. The top string of numbers is the “SavingCF”

for i,v in pairs(TycoonValue.Value.Bin:GetChildren()) do
	local SavingCF = TycoonValue.Value.TycoonBaseplate.CFrame:inverse() * v.PrimaryPart.CFrame
	print(SavingCF)
	table.insert(ServerData[plr].TycoonPlacements, {SavingCF, ItemData.Objects[v.Name][7]})
end
local EncodedData = HttpService:JSONEncode(ServerData[plr])
print(EncodedData)

Take a look at the method I sent, its pretty easy to implement and worked for me.

Oh that’s a bit confusing :confused:
To be honest I never used this method. Maybe it is not possible to encode CFrame? In this case, you could save position and rotation instead of CFrame itself. Also feel free to use grilme’s method too, if it would be easier for you :slightly_smiling_face:

The second baseplate is where I orginally placed the chairs, then I got the one closer to the camera and the chairs went wild, not even on a baseplate.

for i,v in pairs(ServerData[plr].TycoonPlacements) do
		local CFramePosition = CFrame.new(unpack(v.Position))* CFrame.new(TycoonValue.Value.TycoonBaseplate.CFrame:components())
		local GenerateObject = Items:FindFirstChild(v.ObjName):Clone()
		GenerateObject.Parent = TycoonValue.Value.Bin
		GenerateObject:SetPrimaryPartCFrame(CFramePosition)
	end

Hmm, not sure. Take a look at the post I sent (Loading a Model's CFrame at the right Baseplate) the person on there managed to fix it.

Thats what I looked at?

Hmm, I don’t know. Is the code you posted for loading? What code do you use to save?

Here is loading

for i,v in pairs(ServerData[plr].TycoonPlacements) do
	local CFramePosition = CFrame.new(unpack(v.Position))* CFrame.new(TycoonValue.Value.TycoonBaseplate.CFrame:components())
	local GenerateObject = Items:FindFirstChild(v.ObjName):Clone()
	GenerateObject.Parent = TycoonValue.Value.Bin
	GenerateObject:SetPrimaryPartCFrame(CFramePosition)
end

And saving

for i,v in pairs(TycoonValue.Value.Bin:GetChildren()) do
	local SavingCF = {(v.PrimaryPart.CFrame * TycoonValue.Value.TycoonBaseplate.CFrame:Inverse()):components()}
	--print(SavingCF)
	table.insert(ServerData[plr].TycoonPlacements, {Position = SavingCF, ObjName = ItemData.Objects[v.Name][1]})
end

It spreads them out a ton, some not even near the baseplates.

1 Like

Hmm, not to sure.

@Tiffblocks do you have any insight into why it’s not working, since you came up with the method that @Jamie_Jr is trying to implement?

You said you implemented this method yourself. Do you see anything wrong with what I did?

No I implemented the method the Tiffblocks said in the post I sent, I can’t see anything wrong with it, wait for Tiff to reply because she will probably know.

I built a game in 2015 that allowed users to build on a plot, which they could save. I don’t think the saving itself works anymore, as I’m sure it used the old data persistence methods (e.g. Player:SaveString(), Player:LoadString()), but the actual packaging of plot data should still work.

I’ve just taken a look back at the code, and I’m pretty sure I could do much better now, but nevertheless, it may be of some help. See the attached place file.

Construct.rbxl (86.4 KB)

You made that game a day before I joined Roblox :stuck_out_tongue:

1 Like

I think I might have mixed up the order you need to multiply the CFrames in, sorry!

Maybe try these versions?

	local CFramePosition = TycoonValue.Value.TycoonBaseplate.CFrame * CFrame.new(unpack(v.Position))
	local SavingCF = {(TycoonValue.Value.TycoonBaseplate.CFrame:Inverse() * v.PrimaryPart.CFrame):components()}
5 Likes