So I basically want to make a datastore that saves the players hair handle id, so when they join back the script automatically puts the saved id in to the new hairs handle id
Does it have to be in the same server or does it matter if they join a different server? If it only requires the same server, store the id’s in a table or the hats themselves in a folder. If any server, save it in a datastore.
I want to make it even if they join a different server it will still equip it
I’m guessing the place has hair givers/a hair shop?
No its basically a game where and change your outfits
So I would say yes to the hair givers
Save it in a datastore. If you want multiple accessories and an entire outfit like shirts and pants, make it an array. Store the RBXASSETID’s as the outfit value.
When you fetch those results, make sure to grab the proper item out of the array. The saved ID’s in the datastore should work fine (I assume we are using catalog items).
local DSService = game:GetService("DataStoreService")
local AccessoryDS = DSService:GetDataStore("AccessoryDS")
local players = game:GetService("Players")
local accessories
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local res = AccessoryDS:GetAsync("Accessory_"..player.UserId)
print(res)
if type(res) == "table" then
else
res = {}
end
player.CharacterAppearanceLoaded:Connect(function(character)
if #res == 0 then
return
end
local humanoid = character:WaitForChild("Humanoid")
humanoid:RemoveAccessories()
for i, v in pairs(res) do
for index, value in pairs(v) do
local accessory = Instance.new("Accessory")
local handle = Instance.new("Part")
handle.Parent = accessory
local mesh = Instance.new("SpecialMesh")
mesh.MeshId = index
mesh.TextureId = value
mesh.Parent = handle
humanoid:AddAccessory(accessory)
end
end
end)
end)
end)
players.ChildAdded:Connect(function(player)
local character = player.Character
player.CharacterRemoving:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
local data = {}
local accessoryInfo = {}
local accessories = humanoid:GetAccessories()
for i, v in pairs(accessories) do
if v:IsA("Accessory") or v:IsA("Hat") then
if v:FindFirstChildOfClass("MeshPart") or v:FindFirstChildOfClass("Part") then
local handle = v:FindFirstChildOfClass("MeshPart") or v:FindFirstChildOfClass("Part")
if handle:FindFirstChild("Mesh") then
local mesh = handle:FindFirstChild("Mesh")
accessoryInfo[mesh.MeshId] = mesh.TextureId
table.insert(data, accessoryInfo)
end
end
end
end
local res = AccessoryDS:SetAsync("Accessory_"..player.UserId, data)
end)
end)
game:BindToClose(function()
for i, player in pairs(players:GetPlayers()) do
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local data = {}
local accessoryInfo = {}
local accessories = humanoid:GetAccessories()
for i, v in pairs(accessories) do
if v:IsA("Accessory") or v:IsA("Hat") then
if v:FindFirstChildOfClass("MeshPart") or v:FindFirstChildOfClass("Part") then
local handle = v:FindFirstChildOfClass("MeshPart") or v:FindFirstChildOfClass("Part")
if handle:FindFirstChild("Mesh") then
local mesh = handle:FindFirstChild("Mesh")
accessoryInfo[mesh.MeshId] = mesh.TextureId
table.insert(data, accessoryInfo)
end
end
end
local res = AccessoryDS:SetAsync("Accessory_"..player.UserId, data)
end
end
end)
Not sure what possessed me but I decided to make this, it worked when testing.
Ok thank you so much really appreciated