Need help with datastore

so i have a custom character creation and i would like to save the shirt template and pants template but it doesn’t save.

i never used datastore before so i don’t know what to do.

my script:

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")

local ClothingSave = DataStoreService:GetDataStore("ClothingSave")

function Save(Chr, Plr)
      local information = {
      ["Shirt"] = Chr.Shirt.ShirtTemplate;
      ["Pants"] = Chr.Pants.PantsTemplate;
      }
      DataStoreService:SetAsync(Plr.UserId, information)
end

function Load(Chr, Plr)
	local good, info = pcall(function()
		return(DataStoreService:GetAsync(Plr.UserId))
	end)
	print(Plr.Name, "DataStoreRetrivalInformation", good, info)
	Chr.Shirt.ShirtTemplate = info.Shirt
	Chr.Pants.PantsTemplate = info.Pants
end
2 Likes

You need to use the SetAsync and GetAsync functions on ClothingSave (the DataStore) and not on DataStoreService directly.

1 Like

the outfit is still not saving when i leave and rejoin

If you’re trying to save from studio, you need to make sure the “Enable Studio Access to API Services” toggle is enabled in the game settings (the game must be published first).

Does your output show anything?

ServerScriptService.Script:29: attempt to index nil with ‘Shirt’

What does the code for the PlayerAdded/PlayerRemoving look like? It’s possible PlayerRemoving isn’t getting a chance to fire if you’re the only one in game, so you may need to use game:BindToClose() as well as PlayerRemoving.