[PLEASE HELP] NumberValue's Value Via Script Is Shown As NaN When It's Not

I am working on a peace treaty script, the player will be able to send a treaty to end a war with another country. In this treaty, players trade their treasury (which is their money basically). When trading the money, the script just ends up changing the country that sent the treaty request’s treasury/economy to ‘NaN’. I tried to debug it, and I have absolutely no clue what is going on, check the images below. (NOTE: Economy is a numbervalue, and no, theres no child named “Value” in it.)


image

If you know anything about why this is happening, please tell me.

2 Likes

you’re definitely dividing by a 0 somewhere…

I find it a little excessive that you use :FindFirstChild("Values"):FindFirstChild("Economy") after you’ve already accessed them as members.
What’s the code that changes this value?

This is before the calculations even started.

Can you provide shortened snippets of your code where the economy value is set/updated?

Thats the thing, this is before it is even changed at all. But sure.

Is there a template that your game uses for each country? What do economies start off with?

There are calculations for that, each countries starting economy depends on population, land size and way more.

Have you eliminated the possibility that any of those factors may give a starting economy value of NaN?

I checked the economies right before the treaty, they are not NaN. The script just sees it as that for some reason.

The treatyCondition function isn’t doing anything to the economy before it’s printed. The problem is somewhere else. Is treatyCondition the only thing that runs when a treaty happens?

I’m pretty sure it’s the only thing ran, but I will check to make sure.

Nope, nothing. It is the only script running.

Are there any duplicate countries, Values instances, or Economy instances? The print statements use FindFirstChild for the Values and Economy descendants but the increment/decrement part of the treaty uses direct dot notation to access them so it’s unclear if they’re accessing the same child. The debugging code that

might be accessing the legitimate children that don’t have NaN values while this treatyCondition is instead using a NaN version.

There are no duplicates, and I confirmed it is the same child.

If you insert breakpoints, hold all of these relevant instances in variables, and step through each line with the debugger, the Watch widget in Studio will be able to track when the economy changes. I recommend starting at the point where a treaty is first ascertained to be occurring, then going through literally every line until economy becomes NaN in any context.

When I comment out the part that changes the economies, it doesnt make the value NaN, but when they arent commented out, even wayyyy before they even are ran, its NaN. Im so confused.

Found the issue, I dont know why it is the issue, but I found it. Thanks tho.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.