How would I go about using datastore to make a character customization?

So, iv created this method of using leaderstats as a way of telling what hats the player should have, along with shirts and pants, but this method is a huge consumer and is highly unused, I am just curious on how to use datastore as a way of creating character creation?

2 Likes

Well, out of the multiple times I’ve done this for clients, its as simple as making a dictionary and saving it to the datastore… Note this is just off the top of my head so there may be bugs… Nothing to complicated so Im sure it would be a easy fix…


-- Get the datastore

local DataStore = game:GetService("DataStoreService"):GetDataStore("ClothingSave") -- Clothing save can be named whatever you want... 


-- Just use these functions where you need to.. 
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
10 Likes

The thing is, I just don’t understand much of the code.

If you don’t understand the code, learn it first. I would never use code that I don’t understand for a few reasons. The first reason is when bugs arise, you’ll have no idea how to fix it or you’ll have to rely on someone else to fix it. The second reason is you’ll actually be able to do it yourself. I definitely know this one from experience. No matter how long it takes it’s worth your time to learn it. Plus, you’ll be able to write it yourself the next time!

Here’s a few basic tutorials on data stores:
https://developer.roblox.com/articles/Data-store

Anyways, I hope this helped and that you take my advice into consideration.

1 Like

Alright thank you. I will defiantly look into this.

Ooh, I feel like this question was made for me. Conveniently, I’m creating a character customisation system right now. I don’t want to talk too much about it though.

Don’t use leaderstats at all. Character appearance should be stored on the server and once a character is set up, you construct an array and save information about the player’s customised appearance into a DataStore. You can learn about DataStores via the Developer Hub, some posts around here on the DevForum or various tutorials around the net.

For reference, this is my structure of character customisation. It’s in a package so I can take the customised character around places.

image

1 Like

Alright ill take that note. Thank you.

Could you possibly dive a bit deeper and help me better understand?

Alright

Basically before I even begin, you need to go read the wiki page on DataStores, and Dictionaries

Once you understand them, the code seem 100 times easier. Basically what is happening is I am storing values inside of the dictionary then saving it to the player id… once I get it back I can just go back and set all the values of the customization to the player against… Aka loading/saving all of these values.

Sorry for typos and the late response , I am on phone currently

3 Likes