Furnitures load at the wrong place

Hello,
I’ve made a system where players can build a room. They can put furniture in their room, and then it saves on game leaving. However, it doesn’t load furniture correctly when they change rooms (when joining, players doesn’t get the same room). Looking on the ROBLOX docs and google couldn’t help me.

Here’s my saved room :

Here’s the loaded one :


Only 1 furniture is at the correct place…

My code is :

local PlacementServices = {}

local DSS = game:GetService("DataStoreService")
local StandardRoomStore = DSS:GetDataStore("RR_StandardRoomSave")
local BeachRoomStore = DSS:GetDataStore("RR_BeachRoomSave")
local UnderwaterRoomStore = DSS:GetDataStore("RR_UnderwaterRoomSave")

function PlacementServices.LoadData(plr, Room)
	local RoomOwned = Room.Name
	local RoomValue = Room
	local RoomPart = nil
	local DATA = nil
	
	if RoomValue.Parent.Name == "Regular" then
		DATA = StandardRoomStore:GetAsync(plr.UserId)
	elseif RoomValue.Parent.Name == "Beach" then
		DATA = BeachRoomStore:GetAsync(plr.UserId)
	elseif RoomValue.Parent.Name == "Underwater" then
		DATA = UnderwaterRoomStore:GetAsync(plr.UserId)
	end
	
	RoomPart = game.Workspace[RoomOwned].RoomFloor
	
	if DATA == nil then
		return nil
	end
	
	for i,v in DATA do
		local position = nil
		local model = game.ReplicatedStorage.RoomSystem.Furniture:FindFirstChild(v[1])
		
		if model then
			local Clone = model:Clone()
			local ClonePP = Clone.PrimaryPart

			local floorCFrame = RoomPart.CFrame
			
			
			print(v[2])
			
			local POS_CFRAME = CFrame.new(v[2],v[3],v[4])
			position = POS_CFRAME:ToWorldSpace(floorCFrame)
			print(position)

			local cframe = position * CFrame.Angles(v[5],v[6],v[7]) * CFrame.new(0, 0, 0) * CFrame.new(0, 0, 0)
			
			Clone:SetPrimaryPartCFrame(cframe)
			Clone.Parent = RoomPart.Parent.RoomFurniture
			
		end
		
	end
	
end

function PlacementServices.SaveData(plr, Room)
	local RoomOwned = Room.Name
	local RoomValue = nil
	local RoomPart = nil
	local DATA = {}
	
	RoomValue = Room

	RoomPart = game.Workspace[RoomOwned].RoomFloor

	for i,v in pairs(RoomPart.Parent.RoomFurniture:GetChildren()) do
		local model = v
		local floor = RoomPart
		local floorCFrame = floor.CFrame
		local ModelCFrame = model.PrimaryPart.CFrame
		
		local position = ModelCFrame:ToObjectSpace(floorCFrame)
		local rotation = model.PrimaryPart.CFrame.Rotation
		
		print(rotation)
		print(model.PrimaryPart.CFrame.Rotation)

		table.insert(DATA, {model.Name, position.X, position.Y, position.Z, rotation.X,rotation.Y,rotation.Z})
		print(DATA)
	end

	if RoomValue.Parent.Name == "Regular" then
		StandardRoomStore:SetAsync(plr.UserId, DATA)
	elseif RoomValue.Parent.Name == "Beach" then
		BeachRoomStore:SetAsync(plr.UserId, DATA)
	elseif RoomValue.Parent.Name == "Underwater" then
		UnderwaterRoomStore:SetAsync(plr.UserId, DATA)
	end
end

return PlacementServices

If anyone has an idea why it fails to load at the correct place, go ahead…
Thanks…

why are you saving x, y, z as seperate numbers in a table? does DataStoreService seriously not let you save CFrames normally?

Nope. I can’t save data with are comma separated, like CFrames. It throw me an error saying “array can’t be saved to DSS”

Just use ProfileService or any other custom datastore module which lets you save it properly then so you don’t have to go through this hacky and janky mess where you could easily make mistakes.

What’s ProfileService ?
And by other custom datastore module, what do you mean?

Ok found out for profile service, but what are you talking about for the custom datastore modules?

Have you tried printing the whole saved table? This way you can see if its actually saving the data? The datastore you’re using rn probably works but can only save a certain amount of data till the server closes or the player leaves. The way to bypass this is by using something like profileservice.

You’re trying to save a ton of different data through a for loop before the player fully leaves/game closes. So you need a lot of fancy stuff like session locking to allow the player to have their data saved even if it takes a while. ProfileService just does this automatically for you and its really not too different to how regular datastores work.

1 Like

Ima use profile services then I guess. Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.