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: Datastore, why isnt this working?

Previous Thread :: Next Thread 
BuriedBlock is not online. BuriedBlock
Joined: 14 Dec 2009
Total Posts: 3091
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
BuriedBlock is not online. BuriedBlock
Joined: 14 Dec 2009
Total Posts: 3091
31 May 2015 08:22 PM
bump
Report Abuse
BuriedBlock is not online. BuriedBlock
Joined: 14 Dec 2009
Total Posts: 3091
31 May 2015 08:38 PM
b2
Report Abuse
BuriedBlock is not online. BuriedBlock
Joined: 14 Dec 2009
Total Posts: 3091
31 May 2015 08:43 PM
b3
help eek
Report Abuse
BuriedBlock is not online. BuriedBlock
Joined: 14 Dec 2009
Total Posts: 3091
31 May 2015 08:44 PM
Forgot to mention, it's in a server side script located in Workspace.
Report Abuse
BuriedBlock is not online. BuriedBlock
Joined: 14 Dec 2009
Total Posts: 3091
31 May 2015 08:47 PM
b4
Report Abuse
BFFstick00 is not online. BFFstick00
Joined: 25 Oct 2010
Total Posts: 800
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
BuriedBlock is not online. BuriedBlock
Joined: 14 Dec 2009
Total Posts: 3091
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
BFFstick00 is not online. BFFstick00
Joined: 25 Oct 2010
Total Posts: 800
31 May 2015 08:53 PM
stats2[i].Value = DataStore:GetAsync(stats2[i].Name..tostring(newplayer.userId))
tostring() to the rescue!
Report Abuse
Doluan is not online. 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
BuriedBlock is not online. BuriedBlock
Joined: 14 Dec 2009
Total Posts: 3091
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
BuriedBlock is not online. BuriedBlock
Joined: 14 Dec 2009
Total Posts: 3091
31 May 2015 09:02 PM
@BFF Doesnt seem to work, I'm still getting the same exact errors as before.
Report Abuse
BFFstick00 is not online. BFFstick00
Joined: 25 Oct 2010
Total Posts: 800
31 May 2015 09:04 PM
That error would be?
Report Abuse
BuriedBlock is not online. BuriedBlock
Joined: 14 Dec 2009
Total Posts: 3091
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 is not online. 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
BFFstick00 is not online. BFFstick00
Joined: 25 Oct 2010
Total Posts: 800
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
BuriedBlock is not online. BuriedBlock
Joined: 14 Dec 2009
Total Posts: 3091
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
BuriedBlock is not online. BuriedBlock
Joined: 14 Dec 2009
Total Posts: 3091
31 May 2015 09:08 PM
Output in game* on my most recent post
Report Abuse
BFFstick00 is not online. BFFstick00
Joined: 25 Oct 2010
Total Posts: 800
31 May 2015 09:16 PM
Did you upload it to roblox? Did you have it load upon entering?
Report Abuse
BuriedBlock is not online. BuriedBlock
Joined: 14 Dec 2009
Total Posts: 3091
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
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