Trying to save dictionary to datastore

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.

1 Like

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

load it from there…

1 Like

The problem still persists.

30charssssss

1 Like

is charactercustom defined? I don’t see it defined in the script.

1 Like

It’s a dictionary…

charactercustom = {
		["Face"] = face.Texture
	}
1 Like

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

1 Like

Nope. Don’t know why I would need to use BindToClose for this issue.

1 Like

Same error?

Like I said previously,
SetAsync(player.UserId,{}), reset the data… or use a different :GetDataStore key,
check to see if it fixes.

1 Like

I’ve literally already done that. I’m still getting the same error.

1 Like

Try doing:

Face = face.Texture

Then later u can do data.Face or data[1]

1 Like

Same error. I’ve tried the data stuff before posting this and still didn’t work.

1 Like

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

Sorry wrong @

1 Like

Still not working. I did all that and I’m still getting the same error.

1 Like

You did change this part right?

for i,v in pairs(player.Character:GetChildren()) do
		if v:IsA("Decal") then
			face = v
		end
	end
1 Like

Yeah, I just forgot to add .Head to it.

1 Like

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
1 Like

Hey, you fixed the error, but the dictionary is still not being saved.

1 Like

Change the player.Character:GetChildren()
to

player.Character:GetDescendants()

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

1 Like

Nope. Didn’t work.

30charsssss

1 Like

Try using

local success, response = pcall(function()

end)
1 Like