How to make it so your hat selection saves

I dont really know how to summarize my problem for a title so let me explain my problem here:

I have made a hat selection GUI and it works gret, but if you die or reset, you will not spawn with your hat. So you have to re-equip it every time you die. How can i make it so once you select a hat you wont have to re-equip it after you die?

Heres the script ive got:

local chooseHats = game.ReplicatedStorage:WaitForChild("ChooseHats")
local hatsFold = game.ReplicatedStorage:WaitForChild("Hats")

chooseHats.OnServerEvent:Connect(function(player,fullName)
	local character = player.Character
	if fullName == "None" then
		for i,v in pairs(character:GetChildren()) do
			if v:IsA("Accessory") or v:IsA("Hat") then
				v:Destroy()
			end
		end
	else
		for i,v in pairs(character:GetChildren()) do
			if v:IsA("Accessory") or v:IsA("Hat") then
				v:Destroy()
			end
		end
		local accessory = hatsFold:FindFirstChild(fullName)
		if accessory ~= nil then
			local cloneHat = accessory:Clone()
			cloneHat.Parent = character
		end
		
	end
end)



1 Like
game.Players.PlayerAdded:Connect(function(player)
	--stuff
	
	player.CharacterAdded:Connect(function(char)
		-- you can add the hat back here
		
		player.CharacterAppearanceLoaded:Connect(function(char)
			--or here
		end)
		
		char.Humanoid.Died:Connect(function()
			--stuff
		end)
	end)
end)

Create a value and save it somewhere and call it when the player is being re-created.

1 Like