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

My level-up system isn't working. When I change the XP, the level bar doesn't change. Why?

Asked by
3DMage -2
5 years ago
Edited 5 years ago

The one for ServerScriptService is,

game.Players.PlayerAdded:connect(function(Player)
    local Data = Instance.new("IntValue",Player)
    Data.Name = "Data" 
    local XP = Instance.new("IntValue",Data) 
    XP.Name = "XP" 
    XP.Value = 100
    local Level = Instance.new("IntValue",Data) 
    Level.Name = "Level" 
    Level.Value = 1 
    local Tries = Instance.new("IntValue",Data)
    Tries.Value = 10
    Tries.Name = "Tries"

    XP.Changed:connect(function() XPChange(Player,XP,Level) end)

end)

function XPChange(Player,XP,Level)
    if XP.Value >= Level.Value*150  then
        XP.Value = 0
        Level.Value = Level.Value+ 1
    end
end

And the one for the level up GUI is,

while true do
wait()
  local XP = script.Parent.Parent.Parent.Parent.Parent.Data.XP.Value
    local MaxXP = script.Parent.Parent.Parent.Parent.Parent.Data.Level.Value*150
      local math = ( XP / MaxXP )
        script.Parent:TweenSize(UDim2.new(math,0,1,0),"Out","Quad",.25)
end
0
Are you seriously going to just dump your code here without explaining your problem? User#24403 69 — 5y
0
When I change the xp, the bar doesn't move. 3DMage -2 — 5y

1 answer

Log in to vote
0
Answered by
yHasteeD 1819 Moderation Voter
5 years ago
Edited 5 years ago

You know that if you go to level 2 it will multiply level 2 with 150, it will stay in a loop, or if it does not have a maximum level, then it is good for you to do the calculations yourself, but I solved your script.

Errors: When XP changes, it will update the value so it will stay in a loop and will not update bar, Do not leave variables within while true do, if they change you will never get the maximum value you want to do, so put the variables before while true do. You can create Player Variable on local script for not use script.Parent.Parent.Parent.Parent.Parent.... You can not get the value in variables, most of the time will give error.

Fixed script:


SERVER SCRIPT:

--------------------------------------------
local Max_XP = 10000
local Max_Level = 150
--------------------------------------------
game.Players.PlayerAdded:connect(function(Player)

    local Data = Instance.new("IntValue",Player)
    Data.Name = "Data" 
    local XP = Instance.new("IntValue",Data) 
    XP.Name = "XP" 
    XP.Value = 100
    local Level = Instance.new("IntValue",Data) 
    Level.Name = "Level" 
    Level.Value = 1 
    local Tries = Instance.new("IntValue",Data)
    Tries.Value = 10
    Tries.Name = "Tries"

    XP.Changed:connect(function() 
        XPChange(Player,XP,Level) 
    end)
end)

function XPChange(Player,XP,Level)
    if XP.Value >= Max_XP and Level.Value <= Max_Level then
        XP.Value = 0
        Level.Value = Level.Value + 1
   else
    return false;
    end
end

LocalScript:

--------------------------------------------
repeat wait() until game.Players.LocalPlayer
--------------------------------------------

local Player = game.Players.LocalPlayer -- Can only used in LocalScript

local Data = Player:FindFirstChild("Data")
local XP = Data.XP
local Max_XP = 10000

--------------------------------------------

while wait() do

local XPMat = ( XP.Value / Max_XP )
    script.Parent:TweenSize(UDim2.new(XPMat,0,1,0),"Out","Quad",.25)
end
Ad

Answer this question