|
| 31 May 2015 08:10 PM |
local DataStore = game:GetService("DataStoreService"):GetDataStore("Test") game.Players.PlayerRemoving:connect(function(player) local stats = player:FindFirstChild("leaderstats"):GetChildren()
for i = 1, #stats do -- loops print(stats[i].Name) DataStore:SetAsync(stats[i].Name..player.userId, stats[i].Value) end end)
-- Loading game.Players.PlayerAdded:connect(function(newplayer) wait(2) local stats2 = newplayer:FindFirstChild("leaderstats"):GetChildren() for i = 1, #stats2 do stats2[i].Value = DataStore:GetAsync(stats2[i].Name..newplayer.userId) end end)
The error I'm getting is
20:57:10.110 - Workspace.DataStore:16: attempt to index upvalue 'DataStore' (a nil value) 20:57:10.110 - Stack Begin 20:57:10.111 - Script 'Workspace.DataStore', Line 16 20:57:10.111 - Stack End Gold 20:57:23.414 - Workspace.DataStore:7: attempt to index upvalue 'DataStore' (a nil value) |
|
|
| Report Abuse |
|
|
| |
|
| |
|
| |
|
|
| 31 May 2015 08:44 PM |
| Forgot to mention, it's in a server side script located in Workspace. |
|
|
| Report Abuse |
|
|
| |
|
|
| 31 May 2015 08:48 PM |
You can't use numbers in a key. Try: DataStore:SetAsync(stats[i].Name..tostring(player.userId), stats[i].Value) |
|
|
| Report Abuse |
|
|
|
| 31 May 2015 08:51 PM |
@BFF Thanks for the response, but it also errors out on line 16, which happens to be "stats2[i].Value = DataStore:GetAsync(stats2[i].Name..newplayer.userId)" with the same "nil value" error. |
|
|
| Report Abuse |
|
|
|
| 31 May 2015 08:53 PM |
stats2[i].Value = DataStore:GetAsync(stats2[i].Name..tostring(newplayer.userId)) tostring() to the rescue! |
|
|
| Report Abuse |
|
|
Doluan
|
  |
| Joined: 25 Jan 2009 |
| Total Posts: 1064 |
|
|
| 31 May 2015 08:55 PM |
Its really quite simple. "local DataStore = game:GetService("DataStoreService"):GetDataStore("Test")"
the DataStore variable is nil because there is no Datastore named "Test" and im pretty positive you can only create DataStores from Online-ROBLOX-Servers. |
|
|
| Report Abuse |
|
|
|
| 31 May 2015 09:01 PM |
@Doluan I haven't scripted for about 5 months and I'm really not catching on, what do I replace "Test" with?? |
|
|
| Report Abuse |
|
|
|
| 31 May 2015 09:02 PM |
| @BFF Doesnt seem to work, I'm still getting the same exact errors as before. |
|
|
| Report Abuse |
|
|
| |
|
|
| 31 May 2015 09:04 PM |
22:00:35.290 - Workspace.DataStore:16: attempt to index upvalue 'DataStore' (a nil value) 22:00:35.290 - Stack Begin 22:00:35.290 - Script 'Workspace.DataStore', Line 16 22:00:35.291 - Stack End Gold 22:00:40.326 - Workspace.DataStore:7: attempt to index upvalue 'DataStore' (a nil value) |
|
|
| Report Abuse |
|
|
Doluan
|
  |
| Joined: 25 Jan 2009 |
| Total Posts: 1064 |
|
|
| 31 May 2015 09:07 PM |
| Im saying you have to create the datastore before you use it. Also, don't test it out with studio, test it in game and use the in-game output window to see the output of the datastore. |
|
|
| Report Abuse |
|
|
|
| 31 May 2015 09:08 PM |
Okay, lets say that a player has joined for the first time. You need to add if value == nil then -- Change the value to 0 end |
|
|
| Report Abuse |
|
|
|
| 31 May 2015 09:08 PM |
| I get nothing in the output when I do that but yet my leaderstats aren't saving upon rejoining, so it's not working. |
|
|
| Report Abuse |
|
|
|
| 31 May 2015 09:08 PM |
| Output in game* on my most recent post |
|
|
| Report Abuse |
|
|
|
| 31 May 2015 09:16 PM |
| Did you upload it to roblox? Did you have it load upon entering? |
|
|
| Report Abuse |
|
|
|
| 01 Jun 2015 03:55 PM |
I had to go, and I have to go again, but I'll test out everything once more after I upload it to roblox again, and then I'll get back. bumping just incase brb |
|
|
| Report Abuse |
|
|