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: Keys must be strings?

Previous Thread :: Next Thread 
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
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 is not online. 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
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
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 is not online. 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
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
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 is not online. 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
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