So I've got some scripts that allow the user to place down rooms when they click on a button. They are both normal scripts in the workspace. I'm trying to make it so that the placed rooms are saved when they leave and load back in when they rejoin. This is my PlayerEntering script:
function OnPlayerEntered(player) local DS = game:GetService('DataStoreService'):GetDataStore(tostring(player.userId)); local stable = DS:GetAsync('Build') local container = game.Workspace.ModelsContainer for i=1,#stable do local nm = container[stable[i][1]]:Clone(); nm.Parent = workspace; nm.CFrame = CFrame.new(unpack(stable[i][2])) end; end game.Players.PlayerAdded:connect(OnPlayerEntered)
This is my PlayerLeaving script:
local list = {} -- list of placed models local container = game.Workspace.ModelsContainer --where the models are cloned to for index, child in pairs(container:GetChildren()) do list[index] = child -- inserting the models into the array end game.Players.PlayerRemoving:connect(function(player) local DS = game:GetService('DataStoreService'):GetDataStore(tostring(player.userId)); local stable = {}; for i=1,#list do stable[i] = {list[i].Name,{list[i]:GetPrimaryPartCFrame():components()}}; end; DS:SetAsync('Build', stable); end)
At the moment it is not working; do I need to start a server for it to work or is something wrong with it?
You cannot save instances anymore. You will now have to save every single thing, position, size, etc in a table or something.