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

My level up/experience script does not work for some reason?

Asked by
L019 0
4 years ago

When I play test it and change XP's value to 800 from the Properties windows, nothing happen, but my level was supposed to go up + 1

local level = game:GetService("DataStoreService"):GetDataStore("Level")
local xp = game:GetService("DataStoreService"):GetDataStore("XP")
local axp = game:GetService("DataStoreService"):GetDataStore("AXP") -- amount xp needfunction savedata(dataname, playerid, value)

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

game.Players.PlayerAdded:connect(function(player)
    print(player.userId)
 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 700
 xpn.Name = "XpNeeded"
 xpn.Parent = player

 xpz.Changed:connect(function()
  if player:WaitForChild("XP").Value >= player:WaitForChild("XpNeeded").Value then
   levelz.Value = levelz.Value+1
   xpn.Value = xpn.Value+700
   print("xp changed, level changed")
   savedata("Level",player.userId,levelz.Value)
   savedata("XP",player.userId,xpz.Value)
   savedata("AXP",player.userId,xpn.Value)
  else
   print("xp changed, level no change")
   savedata("Level",player.userId,levelz.Value)
   savedata("XP",player.userId,xpz.Value)
   savedata("AXP",player.userId,xpn.Value)
  end
   savedata("Level",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("Level",player.userId,player.leaderstats.Level.Value)
    savedata("XP",player.userId,player.XP.Value)
    savedata("AXP",player.userId,player.XpNeeded.Value)
end)
0
You cant get changed script from script. B_rnz 171 — 4y
0
I can make a script for you if you want. 9mze 193 — 4y
0
Is there another way to script that would result the same? L019 0 — 4y
0
Or can you post a script here so I can replace it? L019 0 — 4y

1 answer

Log in to vote
0
Answered by
L019 0
4 years ago

I got this one My code is just right, but I have to enable API + change the value through the server, not the properties tab.

Ad

Answer this question