level = 1
xp = 0
minxp = 10
local textLabel = script.Parent
textLabel.Text = level
function levelUp()
level = level + 1
textLabel.Text = level
end
function recieveXp()
print("Recieved EXP")
if (xp >= minxp) then
levelUp()
print("You are now level " .. level .. "!")
minxp = math.floor(minxp * 1.2)
print("Next level up at " .. minxp .. " EXP")
end
end
for xp = 0, 1000, 1 do
print(xp .. "/" .. minxp)
recieveXp()
wait(1)
end
I have this simple leveling system here that lets players infinitely level and each level beyond requires more xp. My problem is with my function recieveXp. The for loop below is just to add xp every second. I'm getting a received exp message but the if statement after seems to be showing as false or ignored even when it is true (xp is greater than minimum xp for level up)
The if statement works flawlessly when placed in the for loop in place of the function line but I'd rather make it a function as there will be several events that add exp. I'm relatively new to this, so if you have any suggestions for the best logic for something like this or anything at all, it'd really help.

1 comment
If mattscy's answer helped you and you acknowledge that you should accept his answer.