So i have a system in place to where if your gathered energy greater than half of what the required is, then you have the option to level up.
At level 9, when you level up, you move into the next realm(stronger than the previous 9 levels) , move back to level 1, and basically repeat it like that. each realm has a greater chance of failure of moving into.
At the moment, it always says I break through into the second level every time, but never levels me up nor does it ever fail to level up.
ServerScript V
if TypeOfAction == "Breakthrough" then
local stats = ReturnDataClient(player.Name, "Stats")
local realm = ReturnDataClient(player.Name, "Realm")
local level = ReturnDataClient(player.Name, "Level")
if combatLog[player.Name].Cultivate == true and stats.Qi > stats.requiredQi/50 then
local failchance
stats.BTChance = ((stats.Qi/stats.requiredQi)*100)+stats.BTAdded
if realm == 1 then
failchance = 0
elseif realm == 2 then
failchance = 25
elseif realm == 3 then
failchance = 50
elseif realm == 4 then
failchance = 75
elseif realm == 5 then
failchance = 85
elseif realm == 6 then
failchance = 90
elseif realm == 7 then
failchance = 95
end
local pickChances = {
{
breakthrough = true,
chance = stats.BTChance-failchance
},
{
breakthrough = false,
chance = failchance
},
}
local endResult = {}
for _, data in pairs(pickChances) do
for c = 1, data.chance, 1 do
table.insert(endResult,(data.breakthrough))
end
end
local chosenIndex= math.random(1, #endResult)
local chosen = endResult[chosenIndex]
if chosen == true then
if level < 9 then
level = level+1
stats.Qi = 0
print(player.Name.. " broke through into the level: "..level.."!")
elseif level == 9 then
realm = realm+1
level = 1
stats.Qi = 0
print(player.Name.. " broke through into the realm: "..realm.."!")
end
elseif chosen == false then
if level < 9 then
print(player.Name.. " failed to breakthrough the next level.")
stats.Qi = math.floor(stats.Qi/2)
elseif level == 9 then
print(player.Name.. " failed to breakthrough the next realm.")
stats.Qi = math.floor(stats.Qi/2)
end
end
end
end
Localscript
if not gameEvent and input.KeyCode == X then
RequestActionEvent:FireServer("Breakthrough")
end
Thanks for giving it a read.

4 comments
If you want the level up option to happen if you have energy greater than half of what the required is, then the relevant part of line 7 would need to be stats.Qi > stats.requiredQi/2. I'm not sure what your intention is with the breakthrough chance and fail chance. Are you able to explain in more detail how these two chances are supposed to work?
Also, where you increase the players level on line 51, you are only changing the local level variable and not changing the players data, so the next time this function runs their level will still be 1.
that is the players data, this is all inside the datastore script, ReturnDataClient is just a bad name for it. but i want the chance to succeed to go up as you collect more energy with a base fail chance getting higher each realm
nevermind figured it out. I wasn't capitilizing my stats as its referred to in the table.