Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

2 comments

0

Are you seriously going to just dump your code here without explaining your problem?

0

When I change the xp, the bar doesn't move.

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.