local data= game:GetService("DataStoreService")
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(Character)
LoadCharacter(Character, plr)
end)
end)
function LoadCharacter(Character, plr)
local data
local success = pcall(function()
data = MyDataStore2:GetAsync(plr.UserId)
end)
if not success then
warn("Error while catching "..Character.Name.." data.")
end
end
So basicall,y on load character, just make a dictionary for getting Player data for example
local Information = {
ShirtName = "Yes",
PantsName = "Yes",
HatName = "NoxD",
};
data:SetAsync(plr.UserId,Information)
And to get player data just do
local data
local success = pcall(function()
data = MyDataStore2:GetAsync(plr.UserId)
end)
print(data.ShirtName);
print(data.PantsName);
print(data.HatName);
I believe I’ve solved your issue, I tried to stay consistent with your coding style, and not remove or add too much. Hopefully it helps.
Do note that because you initially add the “default skin” to the player and have a wait(3) it takes 3 seconds before the character’s updated avatar shows. I do not know if you intentionally wanted this or not but I’ve kept it there anyways.
The reason your code on your original post did not work is because you were saving the incorrect data and you were not loading the HumanoidDescription directly based on that data.
Here is the updated code:
local datastore = game:GetService("DataStoreService")
local MyDataStore2 = datastore:GetDataStore("MyDataStore5")
game.Players.PlayerAdded:Connect(function(plr)
print("please wait!")
wait(3)
print("STARTING!")
local datafolder = Instance.new("Folder")
datafolder.Name = "data"
datafolder.Parent = plr
local Shirt = Instance.new("IntValue")
Shirt.Name = "Shirt"
Shirt.Parent = datafolder
local Pants = Instance.new("IntValue")
Pants.Name = "Pants"
Pants.Parent = datafolder
local Hat = Instance.new("IntValue")
Hat.Name = "Hat"
Hat.Parent = datafolder
local humanoiddescription = Instance.new("HumanoidDescription")
humanoiddescription.Name = "PlayersOutFit"
humanoiddescription.Parent = plr.data
humanoiddescription.HatAccessory = "14673292"
Hat.Value = humanoiddescription.HatAccessory
humanoiddescription.Shirt = "2254167941"
Shirt.Value = humanoiddescription.Shirt
humanoiddescription.Pants = "1673964451"
Pants.Value = humanoiddescription.Pants
humanoiddescription.HeadColor = Color3.fromRGB(255, 204, 153)
humanoiddescription.LeftArmColor = Color3.fromRGB(255, 204, 153)
humanoiddescription.LeftLegColor = Color3.fromRGB(255, 204, 153)
humanoiddescription.RightArmColor = Color3.fromRGB(255, 204, 153)
humanoiddescription.RightLegColor = Color3.fromRGB(255, 204, 153)
plr:LoadCharacterWithHumanoidDescription(plr.data.PlayersOutFit)
print("now loading shirt stuff to see if the player had other stuff on")
local PlayerUserId = "player_"..plr.UserId
-- load data
print("loading"..PlayerUserId.." Cloths Data!")
local Data
local suscess, errormessage = pcall(function()
Data = MyDataStore2:GetAsync(PlayerUserId)
end)
if suscess and Data then
wait(2)
print("put the data on")
plr.data.Shirt.Value = Data[1]
plr.data.Hat.Value = Data[2]
plr.data.Pants.Value = Data[3]
wait(1)
plr.data.PlayersOutFit.HatAccessory = Data[1]
plr.data.PlayersOutFit.Shirt = Data[2]
plr.data.PlayersOutFit.Pants = Data[3]
print("changed")
plr:LoadCharacterWithHumanoidDescription(plr.data.PlayersOutFit)
end
end)
local function SaveData(player)
print("Saving...")
local PlayerUserId = "player_"..player.UserId
local shirtdata = player.data.Shirt.Value
local pantdata = player.data.Pants.Value
local hatdata = player.data.Hat.Value
local shirtdata2 = player.data.PlayersOutFit.Shirt
local pantdata2 = player.data.PlayersOutFit.Pants
local hatdata2 = player.data.PlayersOutFit.HatAccessory
local success, errormessage = pcall(function()
print("saved all the values now leaving")
print(shirtdata, pantdata, hatdata)
MyDataStore2:SetAsync(PlayerUserId, {
shirtdata,
pantdata,
hatdata
})
end)
if success then
print("clouths Data Saved Successfully!")
else
print("there was a error saving data")
warn(errormessage)
end
end
game.Players.PlayerRemoving:Connect(function(player)
SaveData(player)
end)
game:BindToClose(function()
for _, player in pairs(game.Players:GetPlayers()) do
SaveData(player)
end
end)