Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to get value of NumberValue?

Asked by 4 years ago
Edited 4 years ago

so basically roblox has these things called NumberValues that hold numbers and NumberValues have an attribute called "Value" where the number is stored

totalCoins is a NumberValue

totalCoins has a value of 5

i want to print the value of totalcoins in console so that 5 is printed

but how do i do it?

2 answers

Log in to vote
0
Answered by 4 years ago

I'm a little confused on what you said but try:

print(totalCoins)

if not

print(totalCoins.Value)
0
tried print(totalCoins), printed "nil", tried print(totalCoins.Value), printed "attempt to index nil with Value" Boungst 5 — 4y
0
check edit for better explanation Boungst 5 — 4y
0
can i have a picture of your explorer? take a screenshot and upload it to imgbb.com and send the link here because honestly, i'm a little confused about what you say guest_20I8 266 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Your answer is quite simple!

Firstly, you'll want to find a way to convert your value into something more feasible. There are several ways to do this, but I recommend first converting the number into a string. You can do so like this:

local tostr = tostring(totalCoins.Value)

So we now have a string variable that holds the value of totalCoins. Our next course of action is to convert that variable into something more readable.

If we're using a LocalScript, I recommend utilizing gui objects for this.

local holder = Instance.new("ScreenGui", game.Players.LocalPlayer.PlayerGui)
local textDisplay = Instance.new("TextLabel", holder)
textDisplay.Text = tostr

Wonderful! Now we have the totalCoins value correctly shown for the player to see.

At this point, the best course of action will be to ask the player very nicely to re-enter the code into a second textbox. We can do that using a few more simple guis:

local input = ""

local button = Instance.new("TextButton", holder)
button.Position = UDim2.new(0,0,0.3,0)
button.Text = "Please enter the text from the TextLabel into the TextBox then click this TextButton!"

local box = Instance.new("TextBox", holder)
box.Position = UDim2.new(0,0,0.6,0)
box.PlaceholderText = "Enter here!" 

button.MouseButton1Click:Connect(function()
    input = box.Text
end)

And now, finally, the final step:

print(5)

Answer this question