I'm trying to make it to where every time you level up the exp you need to go to the next level is 25 more so
level 1 = 100 exp level 2 = 125 exp level 3 = 150 exp
but I don't know what part of the script controls that...
the issue is in the first 6 lines....
function onXPChanged(player, XP, level)
if XP.Value>=level.Value * 100 and level.Value < script.LevelCap.Value then -- issue here
XP.Value = XP.Value - level.Value * 25 --issue here
level.Value = level.Value + 1
end
end
function onLevelUp(player, XP, level)
if player.Character~=nil then
for i = 1,5 do
local fireworks = Instance.new("Part")
fireworks.Shape = 0
fireworks.formFactor = "Symmetric"
fireworks.Size = Vector3.new(1,1,1)
fireworks.BrickColor = BrickColor.Random()
fireworks.CFrame = player.Character.Head.CFrame + Vector3.new(0,2,0)
fireworks.Parent = game.Workspace
game:GetService("Debris"):AddItem(fireworks, 2)
fireworks.Velocity = Vector3.new(math.random(-30,30),math.random(-30,30),math.random(-30,30))
end
end
local m = Instance.new("Hint")
m.Parent = game.Workspace
m.Text = player.Name .. " has gained a level!"
wait(5)
m.Parent = nil
end
function saveScore(player, score)
player:SaveNumber("Lvl", score)
end
function saveScore2(player, score)
player:SaveNumber("XP", score)
end
function saveScore3(player, score)
player:SaveNumber("Gold", score)
end
function saveScore4(player, score)
player:SaveNumber("Strength", score)
end
function saveScore5(player, score)
player:SaveNumber("Vitality", score)
end
function loadScore(player, clickCounter)
local score = player:LoadNumber("Lvl")
if score ~= 1 then
clickCounter.Value = score
else
print("Nothing to load/score was 0")
end
end
function loadScore2(player, clickCounter)
local score = player:LoadNumber("XP")
if score ~= 0 then
clickCounter.Value = score
else
print("Nothing to load/score was 0")
end
end
function loadScore3(player, clickCounter)
local score = player:LoadNumber("Gold")
if score ~= 10 then
clickCounter.Value = score
else
print("Nothing to load/score was 0")
end
end
function loadScore4(player, clickCounter)
local score = player:LoadNumber("Strength")
if score ~= 0 then
clickCounter.Value = score
else
print("Nothing to load/score was 0")
end
end
function loadScore5(player, clickCounter)
local score = player:LoadNumber("Vitality")
if score ~= 0 then
clickCounter.Value = score
else
print("Nothing to load/score was 0")
end
end
function onPlayerEntered(newPlayer)
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
local clicks = Instance.new("IntValue")
clicks.Name = "Level"
clicks.Value = 1
local clicks2 = Instance.new("IntValue")
clicks2.Name = "EXP"
clicks2.Value = 0
local clicks3 = Instance.new("IntValue")
clicks3.Name = "Gold"
clicks3.Value = 10
local clicks4 = Instance.new("IntValue")
clicks4.Name = "Strength"
clicks4.Value = 0
local clicks5 = Instance.new("IntValue")
clicks5.Name = "Vitality"
clicks5.Value = 0
clicks.Parent = stats
clicks2.Parent = stats
clicks3.Parent = stats
clicks4.Parent = stats
clicks5.Parent = stats
stats.Parent = newPlayer
clicks2.Changed:connect(function() onXPChanged(newPlayer, clicks2, clicks) end)
clicks.Changed:connect(function() onLevelUp(newPlayer, clicks2, clicks) end)
newPlayer:WaitForDataReady() -- IMPORTANT: after player.DataReady = true, it won't become false again. You need DataReady to be true for a player before you can load or save data.
-- try loading the player's score
loadScore(newPlayer, clicks)
loadScore2(newPlayer, clicks2)
loadScore3(newPlayer, clicks3)
loadScore4(newPlayer, clicks4)
loadScore5(newPlayer, clicks5)
newPlayer.CharacterAdded:connect(function(c)
c.Humanoid.MaxHealth = newPlayer.leaderstats.Lvl.Value * 20 + 100
c.Humanoid.Health = newPlayer.leaderstats.Lvl.Value * 20 + 100
end)
end
function onPlayerRemoving(player)
print("Attempting to save score for " .. player.Name)
local stats = player:FindFirstChild("leaderstats")
if (stats ~= nil) then
local clicks = stats:FindFirstChild("Level")
local clicks2 = stats:FindFirstChild("EXP")
local clicks3 = stats:FindFirstChild("Gold")
local clicks4 = stats:FindFirstChild("Strength")
local clicks5 = stats:FindFirstChild("Vitality")
if (clicks ~= nil)and(clicks2 ~= nil)and(clicks3 ~= nil)and(clicks4 ~= nil)and(clicks5 ~= nil) then
saveScore(player, clicks.Value)
saveScore2(player, clicks2.Value)
saveScore3(player, clicks3.Value)
saveScore4(player, clicks4.Value)
saveScore5(player, clicks5.Value)
end
end
end
game.Players.PlayerAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerRemoving)
