Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does this not save placed models and load them again?

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?

1 answer

✓ Accepted answer

You cannot save instances anymore. You will now have to save every single thing, position, size, etc in a table or something.

This discussion is preserved as it was. New answers, comments, and votes are closed.