Datastore won't work?

Yes, and thanks. The errors are:

  15:23:05.629  Unable to assign property Value. string expected, got nil  -  Server - Stats:33
  15:23:05.764   is not a valid member of "Enum.Material"  -  Client - LocalMap:64

With this code:

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")

local PlayerData = DataStoreService:GetDataStore("PlayerData")
Players.PlayerAdded:Connect(function(Player)
	-- Statistics
	local Leaderstats = Instance.new("Folder", Player)
	Leaderstats.Name = "leaderstats"
	
	local Money = Instance.new("IntValue", Leaderstats)
	Money.Name = "Money"
	
	local Fans = Instance.new("IntValue", Leaderstats)
	Fans.Name = "Fans"
	-- Multipliers/Cosmetics
	local R = Instance.new("IntValue", Player)
	R.Name = "R"
	local G = Instance.new("IntValue", Player)
	G.Name = "G"
	local B = Instance.new("IntValue", Player)
	B.Name = "B"
	
	local Material = Instance.new("StringValue", Player)
	Material.Name = "Material"
	
	local Data = PlayerData:GetAsync(Player.UserId)
	if Data ~= nil then
		Money.Value = Data[1]
		Fans.Value = Data[2]
		R.Value = Data[3]
		G.Value = Data[4]
		B.Value = Data[5]
		Material.Value = Data[6]
	else
		Money.Value = 0
		Fans.Value = 0
		R.Value = 1
		G.Value = 1
		B.Value = 1
		Material.Value = "CorrodedMetal"
	end
	Money.Value += 5
end)

Players.PlayerRemoving:Connect(function(Player)
	local PlayerDataTable = table.create(0, Player)
	for i, v in pairs(Player.leaderstats:GetChildren()) do
		table.insert(PlayerDataTable, v.Value)
	end
	PlayerData:SetAsync(Player.UserId, PlayerDataTable)
end)

And

local Players = game:GetService("Players")
local Player = game:GetService("Players").LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local Statue = workspace.Statue.Char

local Players = game:GetService("Players")
local Player = game:GetService("Players").LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local Statue = workspace.Statue.Char -- Assuming "Statue" is a Model in the workspace

-- Player Item Functions

function Accessory(v, Material, Color) -- Accessory Function
	local Handle = v:FindFirstChildWhichIsA("MeshPart")
	
	Handle.TextureID = ""
	Handle.Material = Material
	Handle.Color = Color
end

function MeshPart(v, Material, Color) -- Part Function
	v.Material = Material
	v.Color = Color
end

function BaseAppearance(Morph, MorphHumanoid, Scale, Material, Color)
	MorphHumanoid:WaitForChild("BodyHeightScale").Value *= Scale
	MorphHumanoid:WaitForChild("BodyDepthScale").Value *= Scale
	MorphHumanoid:WaitForChild("BodyWidthScale").Value *= Scale
	MorphHumanoid:WaitForChild("HeadScale").Value *= Scale
	
	for i, v in pairs(Morph:GetChildren()) do
		if v:IsA("Pants") then
			v.PantsTemplate = ""
		elseif v:IsA("Shirt") then
			v.ShirtTemplate = ""
		elseif v:IsA("ShirtGraphic") then
			v:Destroy()
		elseif v:IsA("Accessory") then
			Accessory(v, Material, Color)
		elseif v:IsA("MeshPart") then
			MeshPart(v, Material, Color)
		end
	end
	
	MorphHumanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
end
function StatueAppearance()
	-- Variables
	
	Character.Archivable = true
	local CharacterMorph = Character:Clone()
	local MorphHumanoid = CharacterMorph:WaitForChild("Humanoid")
	-- Statue Body Appearance Variables
	
	local Player_Material = Player:WaitForChild("Material").Value
	local Scale = 15
	local Material = Enum.Material[Player_Material]
	local Color = Color3.new(Player:WaitForChild("R").Value, Player.G.Value, Player.B.Value)
	-- Statue Position
	
	CharacterMorph:SetPrimaryPartCFrame(Statue.PrimaryPart.CFrame) -- Set the character's position to match the Statue's position
	-- Revert the statue to normal and set all the changes
	
	Statue:ClearAllChildren()
	CharacterMorph.Parent = Statue
	BaseAppearance(CharacterMorph, MorphHumanoid, Scale, Material, Color)
	Character.Archivable = false
end

StatueAppearance()

Have you checked for the value of Data[6], and Data[5]?

15:23:05.764 is not a valid member of "Enum.Material" - Client - LocalMap:64
this error is unrelated, it’s a client error
with that being said, line 33 has an error, it’s saying that data[6] is nil (it doesn’t exist)
that means that your save is corrupt.
now, i do not know how your game is built, so i cannot tell you how to fix that.
but mayby you can figure it out yourself with the information i provided you with here.
i recommend that you dont use intvalues by the way, try using stringvalues and numbervalues.

Uh this is what the output said

15:33:42.665  5  -  Server - Stats:28
  15:33:42.665  0  -  Server - Stats:30
  15:33:42.665  nil  -  Server - Stats:32
  15:33:42.665  nil  -  Server - Stats:34
  15:33:42.665  nil  -  Server - Stats:36
  15:33:42.665  nil  -  Server - Stats:38

Oh boy…

Probably the error is the way you saving the IntValues or StringValues, but I can’t tell because I don’t know how your game is built

Isn’t an int a number? ooga booga ooga booga

Numbers, but I mean about this:

Players.PlayerRemoving:Connect(function(Player)
	local PlayerDataTable = table.create(0, Player)
	for i, v in pairs(Player.leaderstats:GetChildren()) do
		table.insert(PlayerDataTable, v.Value)
	end
	PlayerData:SetAsync(Player.UserId, PlayerDataTable)
end)

Check for the value of PlayerDataTable.

That’s what I have. ooga booga ooga booga I’ll check.

Ok playerdatatable just returns 1 and 2 because the rest is nil

Then probably there’s the error, because the value of an IntValue can’t be set into nil and the code is saving nil.

I tried a number value but it still didn’t work and if it did save nil it should set to the default, but it doesn’t. I think maybe its cause [1] and [2] are not nil.

Not sure if this helps.

Players.PlayerRemoving:Connect(function(Player)
    local PlayerDataTable = {}
    for i, v in pairs(Player.leaderstats:GetChildren()) do
        table.insert(PlayerDataTable, v.Value) -- Change this line
    end
    print(PlayerDataTable)
    local JSONData = HttpService:JSONEncode(PlayerDataTable)
    PlayerData:SetAsync(Player.UserId, JSONData)
end)

Not sure this is your objective
image

That’s what I got. I need all the values to be default atleast. Also, the json stuff didn’t work, it said that stuff doesn’t exist.

It is not the error, cuz he’s saving from an IntValue and not saving a color but would be a great solution if he’s trying to save colors.

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local HttpService = game:GetService("HttpService")

local PlayerData = DataStoreService:GetDataStore("PlayerData")
Players.PlayerAdded:Connect(function(Player)
	-- Statistics
	local Leaderstats = Instance.new("Folder", Player)
	Leaderstats.Name = "leaderstats"

	local Money = Instance.new("IntValue", Leaderstats)
	Money.Name = "Money"

	local Fans = Instance.new("IntValue", Leaderstats)
	Fans.Name = "Fans"
	-- Multipliers/Cosmetics
	local Color = Instance.new("Color3Value", Player)
	Color.Name = "Color"

	local Material = Instance.new("StringValue", Player)
	Material.Name = "Material"

	local Data = PlayerData:GetAsync(Player.UserId)
	if Data ~= nil then
		Money.Value = Data["Money"].Value
		Fans.Value = Data["Fans"].Value
		Color.Value = Data["Color"].Value
		Material.Value = Data["Material"].Value
	else
		Money.Value = 0
		Fans.Value = 0
		Color.Value = Color3.new(1, 1, 1)
		Material.Value = "CorrodedMetal"
	end
	Money.Value += 5
end)

Players.PlayerRemoving:Connect(function(Player)
	local PlayerDataTable = {}
	for i, v in pairs(Player.leaderstats:GetChildren()) do
		table.insert(PlayerDataTable, v.Value)
	end
	print(PlayerDataTable)
	local JSONData = HttpService:JSONEncode(PlayerDataTable)
	PlayerData:SetAsync(Player.UserId, JSONData)
end)

Forgot to give you HTTPService as a var.

Have you checked for the IntValues inside the leaderstats folder?

Screen Shot 2023-05-28 at 3.51.04 PM

Try with this, maybe is the way you saving the data.

Oh, there is only two IntValues in leaderstats, you saving color and material in Player:

	local Color = Instance.new("Color3Value", Player)
	Color.Name = "Color"

	local Material = Instance.new("StringValue", Player)
	Material.Name = "Material"

Try changing its parent to leaderstats.