Very simple error I can't solve

Hi everyone, this is a wicked quick error and I am terrible at CFrame but here it is.

I made a system where the player can save their objects placed. However, if they save the data, then rejoin, and claim a different plot, the color, loads, same as the block, but the CFrame is off, here is how I am loading it:

cube.CFrame = cube.CFrame * plot.CFrame

1 Like

Does it show an actual error?

Maybe try doing

cube.CFrame = cube.CFrame ^ plot.CFrame

I had some kind of issue where it didn’t position before and I used an exponent and fixed my issue. May it can fix yours! If not then I’m not to sure since I’m not good with CFrames either.

It didn’t work, it said that attempt to power (^) on CFrame. Thanks for the response though. CFrames suck.

Maybe try using SetPrimaryPartCFrame. Thats really all I have. Don’t forget to set a primary part where you think the position is going to be at most accurate though.

Edit: Oh and it has to be a model (I think)

Never mind Forget what I said.

1 Like

My object isn’t a model. That function only goes for models. :frowning:

Thanks for the response. I’ll try to figure it out.

1 Like

Still stuck lol. I’ll keep trying.

I would try saving the object’s offset relative to the plot’s position.

Edit: The code below does not work if the block is at a different orientation :thinking:

local plotPos = game.Workspace.Part.CFrame
local plotPos2 = game.Workspace.Part2.CFrame
local objectPos = game.Workspace.block.CFrame
local calculation = plotPos:ToObjectSpace(objectPos)

--Save here.

--------------

local data = calculation -- Your Data here.
local object = game.ServerStorage.Object:Clone() --Your object here.
object.Parent = workspace

object.CFrame = data * plotPos
3 Likes

I think this should work

With a plot system, you need to understand that there is workspace positioning and cframe, but when handling within the plot itself, it needs to be identifiable within the plot itself like a workspace within workspace

I have not attempted a plot system before, but I would probably use the middle point of the entire plot area as a reference point, and calculate objects positions based off the plot middle point for later saving/loading

1 Like

After testing it, it saves fine. I save it as a string, then convert it into a number, but isn’t working, here’s the code:

loadedmodel.CFrame = tonumber(saved.Pos) * plotbeingviewed.CFrame

It says Invalid argument #1 CFrame expected, got nil.

Saved.Pos is equal to:

tostring(plot.CFrame:ToObjectSpace(objects.CFrame))

Is the plot a part? Try to see if the plot is actually a real instance. Do print(plot.ClassName)

Yes it is a part. I checked. Let me try printing the :ToObjectSpace() part.

Yes, sometimes it doesn’t actually exist so that’s why it gives nil. Also check the other parts that are being loaded in if their real instances/values. No reason for it to return nil if it is a “Part”

Nope it did print. Maybe I can add if plot then.

Still didn’t work. Maybe :ToObjectSpace() makes it a position or something?

let me see the portion of the script

Why are you are doing saved.Pos? It just saved since thats the CFrame

loadedmodel.CFrame = tonumber(saved) *  plotbeingviewed.CFrame`
game.Players.PlayerRemoving:Connect(function(player)
	


	local plot = game.Workspace.Plots:FindFirstChild(player.PlotOwned.Value)

	
	


	
	
	local plotdata = {
		
	}
	
	if plot then
	if game.Workspace.Plots:FindFirstChild(player.PlotOwned.Value) then
		for i, objects  in ipairs(plot:GetChildren()) do
			if objects:IsA("BasePart") and objects.Name ~= "Box" then
			
			table.insert(plotdata,{
					["Name"] = objects.Name,
					
					["Pos"] = tostring(plot.CFrame:ToObjectSpace(objects.CFrame)),
					
					["Color"] = {
						["R"] = objects.Color.R,
						["G"] = objects.Color.G,
						["B"] = objects.Color.B
						
					}
				})
				end
			end
		end
	end
	player.PlotOwned.Value = ""
	
	
	local id = "Player_" .. player.UserId
	local success, err = pcall(function()
	

		
		plotstore:SetAsync(id,plotdata)

	end)
	



	if success then
		print("saved")
	else
		print("no")
	print(err)
	end
	

end)

Loading Error:

local loadedmodel = game.ReplicatedStorage.BuildableObjects:FindFirstChild(saved.Name):Clone()
			
				if loadedmodel then
					print(saved.Pos)
			
				loadedmodel.BrickColor = BrickColor.new(saved.Color.R,saved.Color.G,saved.Color.B)
			
					loadedmodel.Parent = plotbeingviewed
				loadedmodel.CFrame =    tonumber(saved.Pos) *  plotbeingviewed.CFrame

BrickColor works. Same as the object cloning, but not the CFrame.

Wait hold up, after printing the saved.Pos it is nil, let me see whats happening.

Oh you can’t insert a dictionary like that using table.insert

1 Like