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()
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.
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)
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.
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)
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)