Solved Remove the NaN

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the community!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

LoneElf

Active Member
Apr 30, 2017
165
2
18
Hello! So, I have a KitPvP server and it has the KDR feature which is working fine. Now, when a player joins, it shows the KDR as NaN. I am trying to fix it but seam to not be able to. Can someone fix this? Thank you :emoji_slight_smile:
Code:
code_language.skript:
        loop all players:
                wipe loop-player's sidebar
                set name of sidebar of loop-player to "&b&lTrojan Network"
                set score "&8&m-|-----------------&r&8&m---------" in sidebar of loop-player to 14
                set score " &7* &f&lServer" in sidebar of loop-player to 13
                set score "    &7Ping&8: &a%loop-player's ping%ms" in sidebar of loop-player to 12
                set score "    &7Server&8: &aKitPvP" in sidebar of loop-player to 11
                set score "    &7IP&8: &aplay.mctrojan.net" in sidebar of loop-player to 10
                set score "" in sidebar of loop-player to 9
                set score " &7* &f&lPvP Statistics" in sidebar of loop-player to 8
                set score "    &7Kills&8: &a%{kills.count.%uuid of loop-player%}%" in sidebar of loop-player to 7
                set score "    &7Deaths&8: &a%{deaths.count.%uuid of loop-player%}%" in sidebar of loop-player to 6
                set {kdr.%uuid of loop-player%} to {deaths.count.%uuid of loop-player%} / {kills.count.%uuid of loop-player%}
                if {kdr.%uuid of loop-player%} is not set:
                        set {kdr.%uuid of loop-player%} to "0"
                set score "    &7KDR&8: &a%{kdr.%uuid of loop-player%}%" in sidebar of loop-player to 5
                set score " " in sidebar of loop-player to 4
                set score " &7* &f&lPoints" in sidebar of loop-player to 3
                set score "    &7Unclaimed Points&8: &a%{unclaimed.points.%uuid of loop-player%}%" in sidebar of loop-player to 2
                set score "    &7Claimed Points&8: &a%{points.amount.%uuid of loop-player%}%" in sidebar of loop-player to 1
                set score "&8&m-|--------------------------" in sidebar of loop-player to 1

It doesn't show the KDR as 0, but shows NaN. Thanks :emoji_slight_smile:
 
I don't understand. What do you mean that it probably exists? Thanks for the reply though! :emoji_slight_smile:
 
So it literally shows it as "NaN" on scoreboard? Try removing the quotes around 0 to make it set as an integer. I've never had something like this so I'm probably wrong and confused.
 
So, I tried that and gave me the same result: Not A Number (NaN). This is really strange. It has been like this for a while and I don't know how to fix it :/ I am not sure how else you would do this because the code explains itself as it sets it to 0, not NaN. Thanks for the reply @White, I really appreciate your help, and thanks for any future help as it is much appreciated! Thank you!
LoneElf
 
It's because dividing by zero is impossible. When the player's amount of kills is 0 you are dividing the deaths by 0 which can't be done so it will give you NaN. So before dividing, check if the kills is 0 and if it is then just manually display the kdr as 0.

Side note: isn't kdr usually calculated kills / deaths not the other way around like you're doing?
 
Hey - Thanks man! It worked! I am so happy! Thanks for everyone who helped out as I really appreciate everyone here that takes the time to help others. It is really nice. Thank you! <3 :emoji_slight_smile:
 
Status
Not open for further replies.