ModuleScript receiving weird value

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I want to run and return the value of the function in a ModuleScript

  2. What is the issue?
    It gives the error:

ReplicatedStorage.XpMod:4: attempt to perform arithmetic (pow) on table and number
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I searched around for solutions and was out of luck

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Basically i’ve been having a problem with modules, in which i have a function that’s used in multiple scripts. the module is as follows:

local module = {
    calcXp = function(n)
        print(n)
        return math.floor(25*n^1.6)
    end
}
return module

and here’s how i’m running it (after require()ing it) [xS is the module after being required)

 maxXp = xS.calcXp(lvl.Value)

and this is the error I get:

ReplicatedStorage.XpMod:4: attempt to perform arithmetic (pow) on table and number

N does not seem to be a number value, and thus raising it to the 1.6th power would result in an error.

n is a reference/pointer to a table value.

Although it’s weird because I call the function with n as a number, not ever referencing to a table, from what I can see.

The code to get lvl.Value which is what n is in the module is the .Value property of an IntValue.

I don’t think you can mix table values with numbers, try tonumber() hence the error

1 Like

You’re likely calling the module’s function from elsewhere too. Perform a global search for ‘calcXp’.

So I changed it to print what n was, and it returns:

{
    ["calcXp"] = "function"
}

meaning somehow the n variable gets pointed to the module itself,

I fixed the error by changing on of the xpModule:calcXp() to xpModule.calcXp().

What I would like to know is the difference between the two. From what I see one would be referring to one while the other would be running it.

1 Like

Can you share how ‘xS’ was declared?

Might not understand the issue here, but what you are saying is that when you call a function it gives a different variable than what you gave?

maxXp = xS.calcXp(lvl.Value)

Oh, you omitted that information in the original post.

1 Like