Search code examples
luaroblox

How to check how many digits the number value has in roblox studio using a script?


I am trying to make a Computer PIN cracking game in roblox. But I don't know how to check how many digits the number value has, so I come here to ask.

If you guys want to play my game, Click Here

I just did this because I expect that nil can do the job, but no, they can't

if game.ReplicatedStorage.Password.Value == {nil, nil, nil, nil} then
    script.Parent.PlaceholderText = "Four Digits PIN"
elseif game.ReplicatedStorage.Password.Value == {nil, nil, nil, nil, nil, nil} then
    script.Parent.PlaceholderText = "Six Digits PIN"
end


Solution

  • you could use: math.ceil(math.log(game.ReplicatedStorage.Password.Value))

    if this doesn't work for you there are multiple other ways to solve this that are discussed here:

    https://devforum.roblox.com/t/best-way-to-find-how-many-digits-in-a-number/833942