I've got a Data Store script that someone made for me a few months ago because I was confused with how Data Stores worked. Now I've converted my game to FE, and there are only a few errors. Sadly, one of those errors is one of the most crucial parts of the game not working.
I tested the script by loading into the title screen place of my game and resetting the data with the new game button. All of my progress had reset and I was level 1. I rejoined the game, pressed load game, and I was still level 1. So good so far, then I changed my level to 5, waited one minute for the script to save my data, and loaded game again. I loaded in as level 1, which leads me to believe that the script is only not saving.
(the title screen place to the game is not Filtering Enabled, so thats how the data can reset and load into the normal place after pressing load game)
The script is a ServerScript inside of ServerScriptService.
Any help is appreciated, thanks a bunch for reading ^^
script:
local DSService = game:GetService('DataStoreService'):GetDataStore('JoJosJugsStorage')
ID = 65 --If you change this then it will reset everyones stats. [63],[67],[69],[68], [64],[65]
SaveTime = 60 --Shouldn't be less then 60
leaderboardname = "Levelss" --The name of the leader board
StatList = {Vampire = 0, Hamon = 0, Stamina = 100, MaxStamina = 100, Energy = 100, MaxEnergy = 100, Level = 1, XP = 0, CombatDamage = 1, SkillDamage = 1, Defense = 0, SendoKick = 0, TornadoOverdrive = 0, Overdrive = 0, Thunder = 0, Scarlet = 0, Yellow = 0 }
--StartingMoney would give new players the stat StartingMoney with the value 5
--Put any of your values here
--Values are loaded when the player joins and saved when they exit
--Values are also saved every SaveTime seconds
----- You shouldn't need to change anything below this line -----
function CreateValue(Name, Parent, Value) --If value is set to a number then new players will start with that amount.
Value = Value or 0
local savevalue = Instance.new('IntValue', Parent)
savevalue.Name = Name
savevalue.Value = Value
return savevalue
end
function GetValue(uniquekey)
-- GetAsync
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
return GetSaved
end
end
game.Players.PlayerAdded:connect(function(plr)
local uniquekey = ID..plr.userId
local Levelss = Instance.new('IntValue', plr)
Levelss.Name = leaderboardname
for i,v in pairs(StatList) do
local Stat = GetValue(i..uniquekey)
if Stat then
CreateValue(i, Levelss, Stat) --Old player load their value
else
CreateValue(i, Levelss, v) --New player load the default value
end
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = ID..plr.userId
if plr:FindFirstChild(leaderboardname) then
for i,v in pairs(StatList) do
if plr[leaderboardname]:FindFirstChild(i) then
DSService:SetAsync(i..uniquekey, plr[leaderboardname][i].Value)
end
end
end
end)
while wait(SaveTime) do
P = game:GetService("Players"):GetChildren()
for o=1, #P do
if P[o] then
local uniquekey = ID..P[o].userId
if P[o]:FindFirstChild(leaderboardname) then
for i,v in pairs(StatList) do
if P[o][leaderboardname]:FindFirstChild(i) then
DSService:SetAsync(i..uniquekey, P[o][leaderboardname][i].Value)
end
end
end
end
end
end

4 comments
Um.. I think that I already did this, when the player's XP reaches a certain amount, it fires the LevelUpEvent, then increases the stats.
https://gyazo.com/e80ad56431998298d796f53965cdcd8b
I sorta understand though,for a stat inside of a player to be changed, it has to be Replicated. I'll play with it and get it to work eventually, you've put me on the correct path and that's all I needed, thanks
Np, glad to help :)