Hello,
I using Datastore2 in my game and need help with String saving.
Here is my output error:
13:41:59.270 ServerScriptService.Leaderstats:83: attempt to index nil with 'Current_Color' - Server - Leaderstats:83
13:41:59.270 Stack Begin - Studio
13:41:59.270 Script 'ServerScriptService.Leaderstats', Line 83 - function UpdateAllStats - Studio - Leaderstats:83
13:41:59.270 Script 'ServerScriptService.Leaderstats', Line 91 - Studio - Leaderstats:91
13:41:59.270 Stack End - Studio
And here is my leaderstats script:
--// VARIABLES //--
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local Players = game:GetService("Players");
local ServerScriptService = game:GetService("ServerScriptService");
local DataStore = require(ServerScriptService.DataStore2);
--// DataStore Settings //--
local MainKey = "2555bqsj";
DataStore.Combine(MainKey, "Stats", "Color_Buyed", "Player_Color_Buyed");
local function CreateDataTable()
local PlayerData = {
Stats = {
["Level"] = 1;
["Pixels"] = 0;
["Eated_Pixels"] = 0;
["Experience"] = 0;
["Player_Color"] = 1;
};
Color_Buyed = {
["Current_Color"] = {"Fossil"};
};
Player_Color_Buyed = {
["Fossil"] = true;
["Bright_Red"] = false;
["Bright_Blue"] = false;
["Bright_Yellow"] = false;
};
}
return PlayerData
end;
Players.PlayerAdded:Connect(function(Player)
local PlayerData = DataStore(MainKey, Player):Get(CreateDataTable());
local Leaderstats = Instance.new("Folder");
Leaderstats.Name = "Leaderstats";
local Colors = Instance.new("Folder");
Colors.Name = "Colors";
--// STATS //--
local Level = Instance.new("IntValue");
Level.Name = "Level";
local Pixels = Instance.new("IntValue");
Pixels.Name = "Pixels";
local Eated_Pixels = Instance.new("IntValue");
Eated_Pixels.Name = "Eated_Pixels";
local Experience = Instance.new("IntValue");
Experience.Name = "Experience";
---------------
--
local Current_Color = Instance.new("StringValue");
Current_Color.Name = "Current_Color";
--
--// Player_Color_Buyed //--
local Fossil = Instance.new("BoolValue");
Fossil.Name = "Fossil";
local Bright_Red = Instance.new("BoolValue");
Bright_Red.Name = "Bright_Red";
local Bright_Blue = Instance.new("BoolValue");
Bright_Blue.Name = "Bright_Blue";
local Bright_Yellow = Instance.new("BoolValue");
Bright_Yellow.Name = "Bright_Yellow";
---------------
local function UpdateAllStats(UpdatedStats)
-- STATS
Level.Value = DataStore(MainKey, Player):Get(UpdatedStats)["Stats"]["Level"];
Pixels.Value = DataStore(MainKey, Player):Get(UpdatedStats)["Stats"]["Pixels"];
Eated_Pixels.Value = DataStore(MainKey, Player):Get(UpdatedStats)["Stats"]["Eated_Pixels"];
Experience.Value = DataStore(MainKey, Player):Get(UpdatedStats)["Stats"]["Experience"];
--
Current_Color.Value = DataStore(MainKey, Player):Get(UpdatedStats)["Color_Buyed"]["Current_Color"];
-- COLOR BUYED
Fossil.Value = DataStore(MainKey, Player):Get(UpdatedStats)["Player_Color_Buyed"]["Fossil"];
Bright_Red.Value = DataStore(MainKey, Player):Get(UpdatedStats)["Player_Color_Buyed"]["Bright_Red"];
Bright_Blue.Value = DataStore(MainKey, Player):Get(UpdatedStats)["Player_Color_Buyed"]["Bright_Blue"];
Bright_Yellow.Value = DataStore(MainKey, Player):Get(UpdatedStats)["Player_Color_Buyed"]["Bright_Yellow"];
end;
UpdateAllStats(PlayerData)
DataStore(MainKey, Player):OnUpdate(UpdateAllStats)
-- STATS
Leaderstats.Parent = Player;
Level.Parent = Leaderstats;
Pixels.Parent = Leaderstats;
Eated_Pixels.Parent = Leaderstats;
Experience.Parent = Leaderstats;
--
Current_Color.Parent = Leaderstats;
-- COLOR BUYED
Colors.Parent = Leaderstats
Fossil.Parent = Colors;
Bright_Red.Parent = Colors;
Bright_Blue.Parent = Colors;
Bright_Yellow.Parent = Colors;
end);