Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My script isn't returning percentage?

Im trying to make a game that you need exp to level up and I want to get the percent of how much exp they have. I put this line of code in part of my script but i keep ending up with -nan(ind)

local xp = player:WaitForChild("plrInfo"):WaitForChild("EXP")
local xpneeded = player:WaitForChild("plrInfo"):WaitForChild("XPNeeded")

local percentage1 = xp.Value/xpneeded.Value
print(percentage1)
local percentage2 = percentage1*100
print(percentage2)
local percentage3 = math.floor(percentage2)
print(percentage3)

label.Text = percentage3.."%"

2 comments

0

Could you post what prints for the other percentages? You may also have to use tostring() on percentage since it's a number value.

0

your math is right

1 answer

✓ Accepted answer

Your math here is right, so this may be one of the EXP values that are messing this up. Meanwhile, there is a simplified way to find the percentage.

local percentage = math.floor((xp.Value/xpneeded.Value)*100)
label.Text = percentage.."%"

This discussion is preserved as it was. New answers, comments, and votes are closed.