Why isn't this working?

local numb = string.gsub(script.Parent.Name, "button", "")
local num = tonumber(numb)
num.Value -= 1

So basically I’m taking out the “button” from the script’s parent which is named “button5” so I can just have the number 5. Then you can see that I’m trying to turn it from a string to a number and then subtract 1, but it refuses to work no matter what I try. Any ideas on how to fix it?

What errors are you receiving in the console?

The .Value member doesn’t exist in a script variable. Is num a IntValue object or an integer variable defined in the script?

“attempt to index number with Value” but if I remove the .Value, it does nothing

num is simply a number. You cannot index Value of a number.

Does it need to be defined previously? I already defined it with:

local num = tostring(numb)

Hi! Suppose your parent’s name is “button5”. In first line you’re removing “button” from the string, giving the variable numb a value of “5”. Then, you convert this “5” to an integer. Assigning the variable num the integer 5. Then, you’re attempting to change an integers Value for some reason? Integers are a data type and have no propierties. The propierty .Value are usually in IntValues, NumberValues, StringValues… However, in this script you’re dealing with an integer, not an Instance. The final script should be:

local numb = string.gsub(script.Parent.Name, "button", "")
local num = tonumber(numb)
num -= 1

Let me know if it worked!

1 Like

Are you trying to assign num to something else?

Then that means you change it’s value by simply doing num -= 1

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.