Both functions posted return a string.
If you rely on that functionality, you can possibly silence these errors by doing
amount = tonumber(FormatNumber.FormatCompact(amount))
Both functions posted return a string.
If you rely on that functionality, you can possibly silence these errors by doing
amount = tonumber(FormatNumber.FormatCompact(amount))
I was going to recommend this, but I was unable to find any documentation for the library @kry1068 is using. This looks like one of those formatters that condenses numbers to the nearest unit (ie. 100,000,000 becomes 100m), so this may not work if that’s the case.
So I should just remove the “:string”?
Do you rely on :string
being there? I’m not sure how your system works so I didn’t suggest that.
See my latest reply. To verify it, would you mind printing amount
on the line before you declare the amount? That would ultimately tell us what’s causing the type mismatch.
I will send you a link to the documentation quickly. Hold on a second.
Before declaring the amount, I printed the amount and it returned ‘nil’.
The issue is the reassignment.
You declare amount
as a number, then are telling Luau to set it to the return value of FormatCompact
, which is not a number.
Your code will work fine if you do this:
local amountText = FormatNumber.FormatCompact(amount) -- Don't need any type hints here
-- set the text to amountText
So I don’t need to declare amount as a number type. Correct?
You should keep amount
being declared as number
. You can’t reassign it to a string, you have to make a separate variable for the return of FormatCompact.
local function UpdateCurrency(currency: "Seeds" | "Crystal", amount: number)
local amountText = FormatNumber.FormatCompact(amount)
So I did this earlier but it still would send an error. Not that the string could not be changed to a number but that the value must be a number. It was sending the error from the script which defined the format number function.
Can you show the code for that? Something else must be going wrong later down the line.
I can’t currently because my PC started being a potato about 30 minutes ago XD
Feel free to post when you have the code that breaks, something is not right here
Hello, so it has been a day and my PC actually decided to work again. I checked the Roblox Studio and it seems to be working again…
I will test it a few more times to double check that it is definitely working correctly.
And it broke again. Personally, I think that the issue is the actual data store. When a function calls to update a text label once the player joins, it should return a value from the data store. But instead, it returns nil. I think that “nil” is the “string” that can not be converted to a number.
The Data Store I am using is the ProfileService module made by someone else (I am pretty sure it is made by someone else)
This error has been fixed and you can ignore this topic.
Thanks!