Hello , I was trying to make a level system with xp and more , so my problem is that I made it so if you have 100 xp your xp value changes with to 0 and the level value changes to 2 but it doesn’t work and it doesn’t print “Yes” , no errors.
code:
local st = game.Players.LocalPlayer:WaitForChild("exp")
local player = game.Players.LocalPlayer
if st.Value >= player.expneeded.Value then
player.exp.Value = 0
player.lvl.Value = 2
player.expneeded.Value = player.expneeded.Value * player.lvl.Value
print("yes")
end
local st = game.Players.LocalPlayer:WaitForChild("exp")
local player = game.Players.LocalPlayer
local function expFunc()
if st.Value >= player.expneeded.Value then
player.exp.Value -= player.expneeded.Value
player.lvl.Value += 1
player.expneeded.Value = player.expneeded.Value * player.lvl.Value
if st.Value >= player.expneeded.Value then
expFunc()
end
end
expFunc()
print("yes")
end
local player = game.Players.LocalPlayer
game.Players.PlayerAdded:Connect(function(plr)
local lstats = Instance.new("Folder")
lstats.Name = "leaderstats"
lstats.Parent = plr
local exp = Instance.new("IntValue", plr)
exp.Name = "exp"
exp.Value = 0
local lvl = Instance.new("IntValue", plr)
lvl.Name = "lvl"
lvl.Value = 1
local e = Instance.new("IntValue", plr)
e.Name = "expneeded"
e.Value = 100
end)
local st = game.Players.LocalPlayer:WaitForChild("exp")
local player = game.Players.LocalPlayer
local function expFunc()
if st.Value >= player.expneeded.Value then
player.exp.Value -= player.expneeded.Value
player.lvl.Value += 1
player.expneeded.Value = player.expneeded.Value * player.lvl.Value
if st.Value >= player.expneeded.Value then
expFunc()
end
end
expFunc()
print("yes")
end
Why did you put the other part out of the PlayerAdded event?
game.Players.PlayerAdded:Connect(function(plr)
local lstats = Instance.new("Folder")
lstats.Name = "leaderstats"
lstats.Parent = plr
local exp = Instance.new("IntValue", lstats)
exp.Name = "exp"
exp.Value = 0
local lvl = Instance.new("IntValue", lstats)
lvl.Name = "lvl"
lvl.Value = 1
local e = Instance.new("IntValue", lstats)
e.Name = "expneeded"
e.Value = lvl.Value * 100
local debounce = false -- to prevent the function from being repeatedly spammed due to being connected to a .Changed event
local function expChanged()
if not debounce then
debounce = true
repeat
if exp.Value >= e.Value then
exp.Value -= e.Value
lvl.Value += 1
e.Value = 100 * lvl.Value
if exp.Value < e.Value then
break
end
end
print("yes")
task.wait(0.1)
until exp.Value < e.Value
debounce = false
end
end
local function lvlChanged()
if not debounce then
e.Value = 100 * lvl.Value
end
end
exp.Changed:Connect(expChanged)
lvl.Changed:Connect(lvlChanged)
end)