I have problems with my RPG datastore here's save/Load data part of the script :
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStore = DataStoreService:GetDataStore('Data')
-- Settings
local StarterData = {
MaxChar = 5;
LStats = {
Lvl = 1;
XP = 0;
Coins = 0;
};
savedStats = {
Mana = 50;
Health = 100;
Class = "Adventurer";
CharName = "Name";
CurrentPlace = 0;
CurrentPos = Vector3.new(0,0,0)
};
Stats = {
HitChance = 0;
CritChance = 0;
Attack = 0;
MagicAttack = 0;
Defense = 0;
MagicDefense = 0;
Dodge = 0;
};
StatPts = {
Strength = 5;
Intelligence = 5;
Dexterity = 5;
Agility = 5;
Vitality = 5;
};
Char = {
HairStyle = "Default";
HairColor = Color3.new(0,0,0);
Gender = "Boy";
SkinColor = BrickColor.new("Light orange").Color;
Mustache = "None";
Eye = "Default";
EyeColor = Color3.new(0.1,0.05,0)
};
Inventory = {
MaxSlots = 50;
SlotSample = {
Item = "Rock";
Type = "Equipments";
EquipType = "Weapons";
WeaponType = "None";
Stackable = false;
Stack = 0;
};
EquipmentSlotSample = {
Item = "Rock";
WeaponType = "None";
}
};
};
local playersavetable = {};
local AUTO_SAVE_INTERVAL = 180;
-- Functions
local function loadData(Player)
local Data
local s,e pcall(function()
Data = DataStore:GetAsync('UserId:'..Player.UserId)
end)
if s then
print('Loading '.. Player.Name .."'s data was successful!")
else
print('Something went wrong!')
end
if Data then
for num,Slot in pairs(Player.Slots:GetChildren()) do
for name, value in pairs(Data) do
if not Slot.leaderstats:FindFirstChild(name) then return end
Slot.leaderstats[name].Value = value
end
for name, value in pairs(Data) do
if not Slot.StatPts:FindFirstChild(name) then return end
Slot.StatPts[name].Value = value
end
for name, value in pairs(Data) do
if not Slot.savedStats:FindFirstChild(name) then return end
Slot.savedStats[name].Value = value
end
for name, value in pairs(Data) do
if not Slot.Char:FindFirstChild(name) then return end
Slot.Char[name].Value = value
end
end
for _, Folder in pairs(Player.Slots["Slot"..CurrentSlot.Value]:GetChildren()) do
for _,Stat in pairs(Folder:GetChildren()) do
Player[Folder.Name][Stat.Name].Value = Stat.Value
end
end
print('Data has been loaded')
else
print(Player.Name ..'has no data! Generating new data.')
end
end
local function saveData(Player)
if RunService:IsStudio() then return end
local Data = {}
-- Transfers char Current Data to current char slot.
local Slot = Player.CurrentSlot.Value
local Current_Slot = "Slot"..Slot
for _,stat in pairs(Player.Slots[Current_Slot].leaderstats:GetChildren()) do
stat.Value = Player[stat.Parent.Name][stat.Name].Value
end
for _,stat in pairs(Player.Slots[Current_Slot].StatPts:GetChildren()) do
stat.Value = Player[stat.Parent.Name][stat.Name].Value
end
for _,stat in pairs(Player.Slots[Current_Slot].savedStats:GetChildren()) do
stat.Value = Player[stat.Parent.Name][stat.Name].Value
end
for _,stat in pairs(Player.Slots[Current_Slot].Stats:GetChildren()) do
stat.Value = Player[stat.Parent.Name][stat.Name].Value
end
for i,v in pairs(Player.Slots:GetChildren()) do
for _,stat in pairs(v.leaderstats:GetChildren()) do
Data[stat.Name] = stat.Value
end
for _,stat in pairs(v.StatPts:GetChildren()) do
Data[stat.Name] = stat.Value
end
for _,stat in pairs(v.savedStats:GetChildren()) do
Data[stat.Name] = stat.Value
end
for _,stat in pairs(v.Stats:GetChildren()) do
Data[stat.Name] = stat.Value
end
end
local s,e pcall(function()
DataStore:SetAsync('UserId:'..Player.UserId, Data)
end)
if s then
print('Success')
else
warn('Failed to save '.. Player.Name.. "'s data.")
end
end
I always have problems saving data(outside of studio) it keeps printing the error message when I see no errors. I'm pretty sure I didn't exceed the DataStore budget limit, you can check if I'm wrong tho. This DataStore system is based on Mystifine's system https://www.youtube.com/watch?v=at9Yhjt572c

3 comments
That’s great but I don’t want to copy and paste. Also I want to know what’s wrong in my code
Ok, I'll explain you on Discord.
But later, I'll check the advanced DataStore function. And I'll try to explain you how it works. Cya