I made a previous post but I found the answer myself shortly after. All I have to do is inverse a function of mine. However, this inverse function has a square root in it, and sqrt won't work in my script
NOTE: The problem is on line 14, I'm only adding the rest for context
game.Players.PlayerAdded:connect(function(plr) local stats = Instance.new('IntValue', plr) stats.Name = 'leaderstats' local experience = Instance.new('IntValue', stats) experience.Name = 'EXP' experience.Value = 0 local level = Instance.new('IntValue',stats) level.Name = 'Level' level.Value = 1 experience.Changed:connect(function() local q = experience.Value local p = level.Value level.Value = math.floor((1/2) + ((1/10) * sqrt(2*q - 175)) end) end)
The first end is underlined in red. If I add another close parenthesis at the end of line 14 then sqrt is underlined in blue. Can't seem to find the problem
sqrt() is part of the math library
Where you've put sqrt()
, you'll need to replace it with math.sqrt()
because of the library it is a part of.
You may find it nice to know that you can get roots by using fractions with exponents (^
). As an example, x^(1/2)
is the same as math.sqrt(x)
, and similarly x^(1/3)
is a cube root of x
. You'll probably learn this as part of maths before or in college, depending on where you live.
replace line 14 with this:
level.Value = math.floor((1/2) + ((1/10) * math.sqrt(2*q - 175)))
the reason it wont work first of all is that you needed that other parenthesis. Also, sqrt() isn't a function. Usually any functions like that must have "math." before it, like you did with math.floor. So, it has to be math.sqrt().