Hello!
I need help with getting a datastore that saves the player’s current character’s shirt, pants, etc. Right now, it only saves and loads the players accessories, instead of saving and loading everything. Its reading the information correctly off the character, as when it prints in output it shows all the ids correctly - just after its saved and the information is retrieved the face, pants, shirts do not show up.
I have asked this multiple times, with no response - and I really want to get this done, please help me!
Script:
function CharacterSaved(player,saveFile)
local newcharacter = {
character1 = 0,
character2 = 0,
character3 = 0,
character4 = 0,
}
local playerKey = "Player_" .. player.UserId
local character = player.Character
local success, newcharacter = pcall(function()
newcharacter = CharacterDataStore:GetAsync(playerKey)
-- checking if anything is inside the datastore
print(playerKey)
end)
if success then
print("work")
if newcharacter == nil then
--if nothing is there gonna create a new information table
local children = player.Character:GetChildren()
local Acessories = {
}
local key = 0
for i, child in ipairs(children) do
if child:IsA("Accessory") then
-- getting acessories
local meshID = child.Handle:FindFirstChildWhichIsA("FileMesh").MeshId
local TextureID = child.Handle:FindFirstChildWhichIsA("FileMesh").TextureId
key = key + 1
Acessories[key] = { meshID,TextureID}
end
end
local character = {
-- getting the rest of the player's things, this does print their id correctly when printing character
shirtId = player.Character.Shirt.ShirtTemplate,
pantsId = player.Character.Pants.PantsTemplate,
bodycolorId = player.Character:FindFirstChild("Body Colors").HeadColor,
faceId = player.Character.Head.face.Texture,
Acessories
}
-- assigning a safeFile
if saveFile == 1 then
newcharacter = {
character1 = character,
}
end
if saveFile == 2 then
newcharacter = {
character2 = character,
}
end
if saveFile == 3 then
newcharacter = {
character3 = character,
}
end
if saveFile == 4 then
newcharacter = {
character4 = character,
}
end
local success, err = pcall(function()
--saving character
CharacterDataStore:SetAsync(playerKey, newcharacter)
end)
if not success then
print("character was not saved")
end
if success then
print("Character was saved sucessfully")
--checking the information gotten earlier that had not been saved
print(newcharacter)
local character_new = CharacterDataStore:GetAsync(playerKey, newcharacter)
if character_new then
print("theres actually something inside character_new")
print(character_new)
-- checking the datastore too see if it was saved correctly, always ends up with only the acessories being saved.
end
end