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.)
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?
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?
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.
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.