How do I make a datastore save a player's custom character?

I watched a few tutorials on datastores, so I actually understand what a datastore is. The issue is, most of them were for saving leaderstats. What I want to do is make a character customizer that will save a player’s custom avatar in one place and then load it into other separate place. How would I go about doing this? I’ve tried checking out other threads but none of them seem to help. It’s all just a little too complex for me. Help is really appreciated!

1 Like

You could use HttpService:JSONEncode() to convert the avatar data into a string and put that into a data store.

1 Like

I don’t see why you’d need to be using JSONEncode here, since you’re dealing with DataStores not a remote storage via HTTPService

What you can do is store in an Array any properties that the Player is modifying to edit their Avatar. And then use your character customizer to apply those changes again automatically when the Player joins again.

With the help of some threads on the DevForum and some friends I came up with this. The only thing that’s not working if when the player leaves.

local DataStore = game:GetService(“DataStoreService”):GetDataStore(“ClothingSave”)
function Save(Chr, Plr)

local face
for i,v in pairs(Chr.Head:GetChildren()) do
	if v:IsA("Decal") then
		face = v
	end
end
local information = {
	["Shirt"] = Chr.Shirt.ShirtTemplate;
	["Pants"] = Chr.Pants.PantsTemplate;
	["Face"] =face.Texture
}
DataStore:SetAsync(Plr.UserId, information)

end

function Load(Chr, Plr)
	local good, info = pcall(function()
		return(DataStore:GetAsync(Plr.UserId))
	end)
	print(Plr.Name, "DataStoreRetrivalInformation", good, info)
	for i,v in pairs(Chr.Head:GetChildren()) do
		if v:IsA("Decal") then
			v.Texture = info.Face
		end
	end    
	Chr.Shirt.ShirtTemplate = info.Shirt
	Chr.Pants.PantsTemplate = info.Pants
end
game.Players.PlayerAdded:Connect(function(Plr)
	local Char = Plr.CharacterAppearanceLoaded:Wait()
	Load(Char)
end)
game.Players.PlayerRemoving:Connect(function(Plr)
	Save()
end)

I’m to sure how to save the player, but I was thinking of somehow implementing a button in an avatar customizer that saves the avatar to the datastore, although I’m not experienced enough with scripting to figure out how.

4 Likes

When the player presses the save button, it could fire a remote event, and the data store script can listen to the event and call the save function when the event is fired.