|
| 19 Sep 2017 08:11 PM |
I have a script that changes the leaderstat value of a player by setting it to a value stored in a server script. Here is the section of the script that errors.
money = plr.leaderstats:FindFirstChild(getSettings.MoneyName.Value) money.Value = cash.Value:sub(1).."."..cash.Value:sub(2,3)
cash is a variable stored within the script. cash is an IntValue stored in ServerStorage. money is a StringValue stored in leaderstats in the player. plr is successfully defined in a different part of the script.
The error I'm getting is attempt to index field 'Value' (a number value)
Not so sure on what to do. |
|
|
| Report Abuse |
|
|
|
| 19 Sep 2017 08:14 PM |
money must already refer to the value of the Value property. When typing money.Value, you're trying to index the value of that property, which errors.
Also, why not just divide the value by 100 instead of using string manipulation? |
|
|
| Report Abuse |
|
|
|
| 19 Sep 2017 08:17 PM |
| I'm a bit confused on what you mean by that. |
|
|
| Report Abuse |
|
|
|
| 19 Sep 2017 08:19 PM |
Well, I barely read the code at all. Maybe money does refer to an actual object.
Are you positive that the error is reported on the same line as one of the lines that you posted? |
|
|
| Report Abuse |
|
|
| |
|
|
| 19 Sep 2017 08:20 PM |
| What does the cash variable refer to? |
|
|
| Report Abuse |
|
|
|
| 19 Sep 2017 08:21 PM |
| It refers to a value (IntValue) stored in the ServerStorage which I had no trouble with so far. |
|
|
| Report Abuse |
|
|
|
| 19 Sep 2017 08:23 PM |
| One of the two variables (MoneyName or cash) already refers to a literal number value that you're trying to further index. Can you post the assignment of MoneyName and cash (and if it changes throughout the script, the latest one before this code is ran)? |
|
|
| Report Abuse |
|
|
|
| 19 Sep 2017 08:24 PM |
local cash = Instance.new("IntValue", game:GetService("ServerStorage")) MoneyName is stored in a folder called UniversalSettings in ServerStorage. It is NEVER changed in any script as it is set manually in studio. |
|
|
| Report Abuse |
|
|
|
| 19 Sep 2017 08:26 PM |
| cash is always referred to as an IntValue. Whenever anything changes a property of this value, it is through cash.Value. |
|
|
| Report Abuse |
|
|
|
| 19 Sep 2017 08:30 PM |
| The only time 'cash = ' is used is when it is created, so I know it isn't changed throughout the script. |
|
|
| Report Abuse |
|
|
|
| 19 Sep 2017 08:40 PM |
| So far found no solution. I'll try it again tomorrow I have no time to work on this at the moment. |
|
|
| Report Abuse |
|
|
cabbler
|
  |
| Joined: 19 Jun 2015 |
| Total Posts: 735 |
|
|
| 19 Sep 2017 08:44 PM |
> cash.Value:sub(1)
since cash.Value is a number, you can't do the :sub method. it's not a string.
this is what tostring is for |
|
|
| Report Abuse |
|
|
|
| 19 Sep 2017 08:48 PM |
| Actually, no. I've used sub on numbers before. |
|
|
| Report Abuse |
|
|
|
| 19 Sep 2017 08:49 PM |
money = plr.leaderstats:FindFirstChild(getSettings.MoneyName) money.Value = cash.Value:sub(1).."."..cash.Value:sub(2,3) |
|
|
| Report Abuse |
|
|
|
| 19 Sep 2017 08:50 PM |
| Oh, I just checked, sub doesn't work but I've just tried string.sub() and that worked just fine. |
|
|
| Report Abuse |
|
|
cabbler
|
  |
| Joined: 19 Jun 2015 |
| Total Posts: 735 |
|
|
| 19 Sep 2017 08:54 PM |
| well because string.sub purposely handles numbers. I found the relevant error here. |
|
|
| Report Abuse |
|
|
|
| 19 Sep 2017 09:02 PM |
| Well then, now that that's finished, thank you both for helping me out until I found the right way. |
|
|
| Report Abuse |
|
|