" attempt to index number with 'Text' "

I’m getting the error in the title when I try using this code:

local counter = tostring(0)
counter = counter + amount
local countertext = "count: "..counter	
countingTest.Text = countertext

I have tried using the tostring() function to convert the number to text but that still won’t work and the game still counts it as a number so I need help.

image

because you converted the number in a string
then you try to do math with a string

image

fixed :

local counter = 0
counter = counter + amount
local counterText = "count: ".. tostring(counter)
countingTest.Text = counterText

You’re using tostring too early. Strings and numbers can’t be added together, and you’re calling tostring on counter before doing the addition. Try:

local counter = 0
counter = counter + amount
local countertext = ("count: "..tostring(counter))
countingTest.Text = countertext

That still won’t work for some reason it still counts it as a number even when using the tostring() function.

tostring() doesn’t work I have already tried that.

that probably means there is an error outside of this script

No the error happens within that script and I’m 100% certain that the snippet of code that I provided is the issue.

I just tested my own code in an empty script, with the result printing, and it works just fine. Did you try it out? Swap the bottom line of my code for print(countertext) and check the output, it works for me.

Edit: Additionally, I tried using your original code using a textlabel and it reproduced the same error, so you’re right that the error is contained to that snippet. Both mine and @SquarePapyrus12’s both worked on the same textlabel.

does it do any error
if so then tell us

What’s the error, could you also supply the full code? There might be a detail you might’ve missed.

I have tried your code but the issue still occurs.

It only says this: " attempt to index number with ‘Text’ "

idk what’s your problem,
i tried in my side and it worked just fine

i checked if countertext was really a string and yeah it is
as i said, it’s an error outside of the script.

image

If you print the counter variable it successfully prints but when I try to change the text itself it won’t update instead it gives me the error in the title that’s the problem.

In your code somewhere the value “Countertext” Is being changed or you haven’t type in the code correctly,
Again, please supply more than just a snippet so we can identify if that’s the case.

¯_(ツ)_/¯

1 Like

I have not changed the countertext variable anywhere so that snippet of code is the one that errors.

In that case, the snippets of code supplied by the other developers should fix your problem.

Looking at the error message, it sounds like countingTest might be a number.

2 Likes
local counter = 0
counter = counter + amount
local counterText = "count: ".. tostring(counter)
script.Parent.Text = counterText -- u need to write the whole path, while changing Gui property