'Players.endersam777.PlayerGui.Currency.Money.LocalScript:5: attempt to call a number value
So, I was making something like the currency on leaderboard will be on a TextLabel. How can I make something like it will not be showing 0 but 0$? Because if I will put script.Parent.Text = player.leaderstats.Coins.Value"$" it will not work. Script:
local player = game:GetService("Players").LocalPlayer
script.Parent.Text = player.leaderstats.Coins.Value
Solution 1:[1]
You can concatenate strings using ..
Example:
local player = game:GetService("Players").LocalPlayer
script.Parent.Text = tostring(player.leaderstats.Coins.Value).."$"
Checkout the PIL 3.4 for more examples.
Solution 2:[2]
The other answer tells you how to fix your problem, so I'll just add some additional information.
The reason you are getting an error is because of how lua calls functions. Usually you would call a function like this :
print("hello world")
... where you use parentheses around the arguments. However, when you only provide one argument to the function, you can omit the parentheses and it will still work :
print "hello world"
So in your code, because you have two values right next to each other :
? value 1 ? value 2
script.Parent.Text = player.leaderstats.Coins.Value"$"
... the interpreter sees this and thinks that value 1 is a function, and value 2 is the argument you are passing to it, and it is throwing an error because player.leaderstats.Coins.Value
is not a function, it's a number. That's why you are getting the error Attempt to call a number value
(like a function).
And some other alternatives for concatenating strings can be found in this answer : https://stackoverflow.com/a/21792185/2860267
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | F. Linnenberg |
Solution 2 | Kylaaa |