|
| 17 Dec 2014 04:18 PM |
I am testing out saving methods with the data store, but now I keep receiving the error "Keys must be strings."
There is no line number, but it is just red text.
Key (I even changed it): "stats_" .. tostring(player.userId) And I added print(key) which prints "stats_-1" (meaning that it is a string).
FYI the -1 is when you get the userId of a player in test servers. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 17 Dec 2014 04:20 PM |
| It's concatenated which means it is definitely a string. You might be messing up somewhere other than you expect, but just to make sure, use print(type()) to make sure you haven't somehow changed it to something other than a string .-. |
|
|
| Report Abuse |
|
|
|
| 17 Dec 2014 04:29 PM |
game.Players.PlayerRemoving:connect(function(p) local profile = {} local stats = p:FindFirstChild("StatStorage") local key = "stats_" .. tostring(p.userId) if stats then profile = {f = stats.Freezes.Value, t = stats.Thaws.Value, h = stats["Max Hit Points"].Value} local weps = getWeapons(p) print(unpack(weps)) profile[4] = weps datastore:UpdateAsync(key, function(lastVal) local newVal = profile return newVal; end) end end)
This is the playerRemoving function. I don't think there should be anything wrong with it (other than the possibility of exceeding the 2 ^ 16 character limit or attempting to save a table, which previously worked). |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 17 Dec 2014 04:30 PM |
> profile[4] = weps
This is the line it doesn't like. Your keys must all be strings or they must all be numbers, no mixing of the two for Data Store. |
|
|
| Report Abuse |
|
|
|
| 17 Dec 2014 04:36 PM |
So I can't save it because there is another table inside of "profile"?
Or do you mean I can't do this:
{f = 0, t = 0, h = 100, "String"}
?
And if that is the case then could I use JSON encoding? |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 17 Dec 2014 04:39 PM |
| If you need a mixed style table, then you will need JSON style encoding. |
|
|
| Report Abuse |
|
|