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

Save the position color and material of all parts in a model and load?

I want to store and load all the pieces in a model, but I do not know how to do that. I thought about doing something like this:


local DSS = game:GetService("DataStoreService")

local datastore = DSS:GetDataStore("GeneralSaveData", "Players")

function generateDataKey(player)
    local ret = ("uid_" .. player.userId)
    return ret
end

function generateDataTable(player)
    local dataTable = {
		
        game.Workspace.TestModel:GetChildren()
		
    }
    return dataTable
end

function saveDataForPlayer(player)
    local key = generateDataKey(player)
    local data = generateDataTable(player)
    datastore:SetAsync(key, data)
end

function inputDataToPlayer(player, data)
	if data ~= nil then
		
	
    for datatoload, data in pairs(data) do
	
	data.Parent = game.Workspace.TestModel
	
end
end

	
end
end

function loadDataForPlayer(player)
    local key = generateDataKey(player)
    local data = datastore:GetAsync(key)
    inputDataToPlayer(player, data)
end

game.Players.PlayerAdded:connect(function(player)
	loadDataForPlayer(player) 
	wait ()
	while true do
		wait (60)
     	saveDataForPlayer(player) 
	end
end)

game.Players.PlayerRemoving:connect(saveDataForPlayer) 

But this script obviously doesn't work. How do you solve this problem?

If there are any I would be happy about tutorial links or similar I did not find any

1 answer

✓ Accepted answer

Well, you can't save models directly to a DataStore, but you can save values to it.

If this is a tycoon type game, the items will be the same across all servers. You would want to assign an id (or a name), to each item. This will help the code tell which item to save/load.

You would then want to save tables, each containing the id (or name) of the item, the position, the color, and any other thing you would like.

Then, when you load the player data, you read the table, create a new model based off of the id, and set up the other things you want from the other values.

Hope this helps! If you have any questions, please ask.

1 comment

0

How would you save a table can i use my script from above?

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