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…