generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Unexpected Error?

Previous Thread :: Next Thread 
loltutorial is not online. loltutorial
Joined: 29 Jul 2017
Total Posts: 11
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
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
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
loltutorial is not online. loltutorial
Joined: 29 Jul 2017
Total Posts: 11
19 Sep 2017 08:17 PM
I'm a bit confused on what you mean by that.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
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
loltutorial is not online. loltutorial
Joined: 29 Jul 2017
Total Posts: 11
19 Sep 2017 08:19 PM
Yes. It is on line 56.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
19 Sep 2017 08:20 PM
What does the cash variable refer to?
Report Abuse
loltutorial is not online. loltutorial
Joined: 29 Jul 2017
Total Posts: 11
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
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
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
loltutorial is not online. loltutorial
Joined: 29 Jul 2017
Total Posts: 11
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
loltutorial is not online. loltutorial
Joined: 29 Jul 2017
Total Posts: 11
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
loltutorial is not online. loltutorial
Joined: 29 Jul 2017
Total Posts: 11
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
loltutorial is not online. loltutorial
Joined: 29 Jul 2017
Total Posts: 11
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 is not online. 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
loltutorial is not online. loltutorial
Joined: 29 Jul 2017
Total Posts: 11
19 Sep 2017 08:48 PM
Actually, no. I've used sub on numbers before.
Report Abuse
masterblokz is not online. masterblokz
Joined: 17 Nov 2010
Total Posts: 9517
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
loltutorial is not online. loltutorial
Joined: 29 Jul 2017
Total Posts: 11
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 is not online. 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
loltutorial is not online. loltutorial
Joined: 29 Jul 2017
Total Posts: 11
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image