Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

"attempt to index a number value" DataStore?

Asked by 6 years ago
01local DataStoreService=game:GetService("DataStoreService")
02local DataStore=DataStoreService:GetDataStore("Player_Data")
03game.Players.PlayerAdded:connect(function(Player)
04 
05    local gameData;    
06    local Stats=Instance.new('Folder')
07    Stats.Name="plrData"
08    local Money=Instance.new('NumberValue',Stats)
09    Money.Name="Credits"
10    Stats.Parent=Player
11    local SpecialMoney=Instance.new('NumberValue',Stats)
12    SpecialMoney.Name = "Resort Tokens"
13    local ownedWeapons=Instance.new('Folder',Stats)
14    ownedWeapons.Name = "ownedWeapons"
15 
View all 70 lines...

On Line 31, it gives me the title error. How could I clone the player's data if they played already?

1 answer

Log in to vote
0
Answered by
gullet 471 Moderation Voter
6 years ago

As the error said you're trying to index a number. PlayerData=DataStore:GetAsync(tostring(Player.UserId) returns a number, not a NumberValue object. You can't call Clone on a number. Perhaps you meant to do Player.plrData.Credits.Value = PlayerData

0
How do I clone the folder from the DataStore to the player? ShutokouBattle 227 — 6y
0
The DataStore didn't contain a folder, if you have a folder then you can use Clone. But in this case you had a number. You can't save objects like folders in DataStore. gullet 471 — 6y
0
Well how could I save plrData? ShutokouBattle 227 — 6y
0
Save it as something else and not a folder, a table perhaps or a key for each value. gullet 471 — 6y
View all comments (2 more)
0
I want to use a table. How do I use tables with DataStores? (sorry for excessive asking xd) ShutokouBattle 227 — 6y
0
You just use them... Try having a look at the wiki for datastore and table if you're unfamiliar with them. gullet 471 — 6y
Ad

Answer this question