Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

My script isn't returning percentage?

Asked by
Zrxiis 26
7 years ago

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.."%"
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. PreciseLogic 271 — 7y
0
your math is right Perci1 4988 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

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.."%"
Ad

Answer this question