local saveslot1 = game:GetService("DataStoreService"):GetDataStore("SlotSave1")
function SaveData1(player,character)
local face
for i,v in pairs(player.Character:GetChildren()) do
if v:IsA("Decal") then
face = v
end
end
charactercustom = {
["Face"] = face.Texture
}
saveslot1:SetAsync(player.UserId,charactercustom)
end
function LoadData1(player,Character)
local success,response = pcall(
saveslot1.GetAsync,
saveslot1,
player.UserId
)
for i,v in pairs(player.Character.Head:GetChildren()) do
if v:IsA("Decal") then
v.Texture = charactercustom.Face
end
end
end
game.Players.PlayerAdded:Connect(function(player)
repeat wait() until player.Character
LoadData1(player,player.Character)
end)
game.Players.PlayerRemoving:Connect(function(plr)
repeat wait() until plr.Character
SaveData1(plr,plr.Character)
end)
I get an "Attempt to index nil with “Face”, on v.Texture = charactercustom.Face.
You are looping through the characters children. You won’t find any decals unless you instanced a decal there. Therefore when you call SaveData1, face will be nil. To fix this you should just write “Face” = character.Head.Face.Texture
sometimes old attempts glitch the datastore so you must wipe the datastore, if it still persists or doesn’t error afterwards try adding a bindtoclose
local success,response = pcall( saveslot1.GetAsync, saveslot1, player.UserId )
I haven’t tried that method if that even works,
I would do local x = saveslot1:GetAsync(player.UserId)
So the data might be saving but when loaded, it loads nil, and again, data might not be saving because player removing is not enough, bindtoclose is very helpful for saving
You are never defining “charactercustom” when the player joins therefore it is trying to index a nil dictionary. Try something like this to write the data to a value while wrapping the function in a pcall.
local charactercustom
local suc,err = pcall(function()
charactercustom = saveslot1:GetAsync(player.UserId)
end
if charactercustom then
for i,v in pairs(player.Character.Head:GetChildren()) do
if v:IsA("Decal") then
v.Texture = charactercustom.Face
end
end
end
This is probably the issue as in getchildren it doesn’t find any decals withing the character model so the face is nil. The decal is inside somewhere in the head so GetDescencants would work