It's a Leveling Script. It doesn't give any Error on Click, but it doesn't reduce XP or give Levels. Can someone help?
local plr = script.Parent.Parent.Parent.Parent.Parent
script.Parent.MouseButton1Click:Connect(function()
local xps = plr.leaderstats.XP.Value
local Level = plr.leaderstats.Level.Value
if Level == 0 then
if xps >= 10 then
Level = 1
xps = xps - 10
end
elseif Level == 1 then
if xps >= 15 then
Level = 2
xps = xps - 15
end
elseif Level == 2 then
if xps >= 22 then
Level = 3
xps = xps - 22
end
elseif Level == 3 then
if xps >= 34 then
Level = 4
xps = xps - 34
end
elseif Level == 4 then
if xps >= 51 then
Level = 5
xps = xps - 51
end
elseif Level == 5 then
if xps >= 76 then
Level = 6
xps = xps - 76
end
elseif Level == 6 then
if xps >= 114 then
Level = 7
xps = xps - 114
end
elseif Level == 7 then
if xps >= 171 then
Level = 8
xps = xps - 171
end
elseif Level == 8 then
if xps >= 256 then
Level = 9
xps = xps - 256
end
elseif Level == 9 then
if xps >= 385 then
Level = 10
xps = xps - 385
end
elseif Level == 10 then
if xps >= 577 then
Level = 11
xps = xps - 577
end
elseif Level == 11 then
if xps >= 866 then
Level = 12
xps = xps - 866
end
elseif Level == 12 then
if xps >= 1300 then
Level = 13
xps = xps - 1300
end
elseif Level == 13 then
if xps >= 1950 then
Level = 14
xps = xps - 1950
end
elseif Level == 14 then
if xps >= 2910 then
Level = 15
xps = xps - 2910
end
elseif Level == 15 then
if xps >= 4380 then
Level = 16
xps = xps - 4380
end
elseif Level == 16 then
if xps >= 6560 then
Level = 17
xps = xps - 6560
end
elseif Level == 17 then
if xps >= 9850 then
Level = 18
xps = xps - 9850
end
elseif Level == 18 then
if xps >= 14770 then
Level = 19
xps = xps - 14770
end
elseif Level == 19 then
if xps >= 22160 then
Level = 20
xps = xps - 22160
end
elseif Level == 20 then
script.Parent.Text = "Already maxed"
wait(0.5)
script.Parent.Text = "Level Up!"
end
end)
I think your problem is you are trying to modify player stats via local scripts. This will not work as the server is responsible for handling anything besides the character itself. You are also approaching it in a harder way. Based on your xp's required to level up you have a ~1.5 exponential growth to them. Instead of checking each level and each required exp for that level, just use some math to determine how much exp they would need to level up at their current level
-- In a script located anywhere game.Players.PlayerAdded:Connect(function(player) -- Connect function to players joining local stats = player:WaitForChild("leaderstats") -- Wait for leaderstats local experience = stats:WaitForChild("XP") -- Wait for xp local level = stats:WaitForChild("Level") -- Wait for level experience:GetPropertyChangedSignal("Value"):Connect(function() -- Detect when experience value is changed, and when it is run below code if experience.Value >= 10 * (1.5 ^ level.Value * (1.5 ^ 1 - 1)) / (1.5 - 1) then -- Basically this checks to see if the players experience is equal or greater to the required exp for that level. I will bust the math down below experience.Value = experience.Value - 10 * (1.5 ^ 4 * (1.5 ^ 1 - 1)) / (1.5 - 1) -- If so, remove that much exp from the player (exactly that amount as not to remove exp over the required) level.Value = level.Value + 1 -- Level player up end end) end) -- This function will run any time the player gets exp, and if they have enough it will level them up. --Now to explain the math -- The formula you need looks like 10 * (1.5 ^ level.Value * (1.5 ^ 1 - 1)) / (1.5 - 1) -- It looks like this when you havent inputted your values. -- b * (r ^ k * (r ^ 1 - 1)) / (r - 1) -- b = the base experience required, in your case, 10 -- r = the exponential growth, in your case, 1.5 -- k = the current level --With this in mind, you can change the values from b and r. Changing b will simply require more exp to start with, but each level up would be the same difference from having 1 or 1000. Changing r will make each level up require more or less experience than the last. So making that number lower will result in each level up only costing slighly more than the last, or making it bigger will make each level up cost way more. Using 1.5 is pretty close to your current formula.