Converting NumberValue into String

  1. What do you want to achieve? Keep it simple and clear!
    I want to know how to convert a number value into a string.

  2. What is the issue? Include screenshots / videos if possible!
    I don’t know how to, but I know you have to use tostring()

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Yes, I’ve tried but not sure how you would implement into this code.

Basically I’m trying to see if a player’s kill is a larger then every other players kill. And in order to do that I need to get their kill value, but I’m not sure how I would covert the numberValue into a string.

This is my code.

if #plrs[1].leaderstats.Kills.Value > plrs.leaderstats.Kills.Value  then

I’m not sure where about I would convert it into a string.

You could do something like

table.sort(plrs, function(a, b)
    return a.leaderstats.Kills.Value > b.leaderstats.Kills.Value
end)

local leader = plrs[1]

so that the first player in the table is always the kill leader.

Does this convert into a string, so that it can the compare the values?

Why does it need to be a string?

Ok, I’m not sure if I’m doing it right but if I did my code above, the output would print
[attempt to get length of a number value]
Why is this the case?

#plrs[1].leaderstats.Kills.Value

Kills.Value is already a number, containing how many kills plrs[1] has. You don’t need to get the length of it.

I am not sure since i didn’t use Lua for ages now, but this should give you an idea.

local Kills = Kills.Value.ToString() -- Converts it to string
print(#Kills)

In Lua numbers aren’t objects. You would just use tostring(Kills.Value) but here it isn’t necessary. Although OP should have asked about their problem (getting the player with the most kills) rather than their attempted solution (turning a NumberValue into a string)

I won’t argue with that since i have been using C# for years now, But isn’t the idea somewhat correct?

Yes it is, although numbers aren’t objects, like they don’t have those methods directly on them

Think Convert.ToInt32 (and such) instead

1 Like

Ok, your method gets the player with the most kills, but why does it keep showing in the output. attempt to get length of a number value?