How to equip a hat and have the game remember it with datastores?

Hey there! I have a hat system in my game, and I want to make it where you can equip a hat once in the game, and the game will remember that and it will clone the same hat on your character when you join back. I’m not really sure where to start as I am new to datastores. If some one could help me out, that would be great!

Heres the hat equip script:

local hatFolder = game:GetService("ServerStorage").Hats

	local hatClone = hatFolder["The True King"]:Clone()
	hatClone.Parent = plr.Character
	if plr.Character:FindFirstChild("EgglessFryingPanAccessory") then


	if plr.Character:FindFirstChild("Black Top Hat with Red Band") then
		plr.Character["Black Top Hat with Red Band"]:Destroy()


	if plr.Character:FindFirstChild("BlackFedora") then


	if plr.Character:FindFirstChild("KnightHelmet") then


Hey! Save a string value in the DataStore.

It can be like something like “EquippedHat”.

Make a PlayerAttribute and when a hat is equipped, change that PlayerAttribute to a number or string you’d like, then DataStore can grab that value from player to save it.

Then, through a Server Script, get the data from DataStore and based on what’s the string value, clone a hat to that specific player!

If you want to, I could make a system like this in a Roblox Place, but this is my method personally :))

Sounds like a step in the right direction! I’ll try to implement that, and if I need any more guidance I’ll let ya know!