Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why does my level up system not save the leaderstats?

Asked by 4 years ago

Im guessing this is a simple solution but i cant figure it out.

Script:

local level = game:GetService("DataStoreService"):GetDataStore("Levelsonezo")
local xp = game:GetService("DataStoreService"):GetDataStore("XPonezo")
local axp = game:GetService("DataStoreService"):GetDataStore("AXPonezo") --Stands for amount of xp needed to level up.

function savedata(dataname, playerid, value)
 game:GetService("DataStoreService"):GetDataStore(dataname):SetAsync(playerid, value)
end

game.Players.PlayerAdded:connect(function(player)
 local leader = Instance.new("Folder")
 leader.Name = "leaderstats"
 leader.Parent = player
 local levelz = Instance.new("IntValue")
 levelz.Value = level:GetAsync(tostring(player.userId)) or 1
 levelz.Name = "Level"
 levelz.Parent = player:WaitForChild("leaderstats")
 local xpz = Instance.new("NumberValue")
 xpz.Value = xp:GetAsync(tostring(player.userId))
 xpz.Name = "XP"
 xpz.Parent = player
 local xpn = Instance.new("IntValue")
 xpn.Value = axp:GetAsync(tostring(player.userId)) or 1000
 xpn.Name = "XpNeeded"
 xpn.Parent = player

 xpz.Changed:connect(function()
    print("+XP SAVING")
  if player:WaitForChild("XP").Value >= player:WaitForChild("XpNeeded").Value then
   levelz.Value = levelz.Value+1
    xpn.Value = xpn.Value + 500
   xpn.Value = xpn.Value
   savedata("Levels",player.userId,levelz.Value)
   savedata("XP",player.userId,xpz.Value)
   savedata("AXP",player.userId,xpn.Value)
  else
   savedata("Levels",player.userId,levelz.Value)
   savedata("XP",player.userId,xpz.Value)
   savedata("AXP",player.userId,xpn.Value)
  end 
  savedata("Levels",player.userId,levelz.Value)
  savedata("XP",player.userId,xpz.Value)
  savedata("AXP",player.userId,xpn.Value)
 end)
end)

game.Players.PlayerRemoving:connect(function(player)
 savedata("Levels",player.userId,player.leaderstats.Level.Value)
 savedata("XP",player.userId,player.XP.Value)
 savedata("AXP",player.userId,player.XpNeeded.Value)
end)

1 answer

Log in to vote
0
Answered by 4 years ago

When loading data, you appear to be using the DataStore "Levelsonezo," while you only pass "Levels" to your save function; which, in turn, saves the Data to "Levels" and not "Levelsonezo."

0
ok thanks I`ll try it out now DaggerSaber 14 — 4y
0
Nope it still does not save DaggerSaber 14 — 4y
0
You are also applying tostring to the UserId when you load the data, but not when you save. IStarConquestI 414 — 4y
0
ok im gonna try that too when i have time DaggerSaber 14 — 4y
0
Ok so now with that it saves the XP but it does not save the Level and the XpNeeded DaggerSaber 14 — 4y
Ad

Answer this question