DataStore Not Working

Hello everyone. I am trying to make a datastore for a game I am making. I’m new to scripting and can’t get the data to save in the game. The game is published and I tested the datastore on the published game and it didn’t save my leaderstats. I believe the problem is in my variables at the top of the script. The code is in a script, not a local script.

6 Likes

First of all, you’re trying to get a local player in lines 2 and 3, which is impossible on server. Secondly, you misspelt SetAsync in line 27. You might wanna call :WaitForChild() on leaderstats because the folder most likely doesn’t load in as fast as you try to access it.

4 Likes

Ok, how would I get my player leaderstats folder as a variable. The folder saves to each player.

2 Likes

So you’ve got PlayerAdded event right; That’s your way of getting the player

local players = game:GetService("Players") --you should always call :GetService() when trying to access services

players.PlayerAdded:Connect(function(player) --that's where player comes from
    local leaderstats = player:WaitForChild("leaderstats")
    local points = leaderstats.Points
    local rebirths = leaderstats.Rebirths
end)
4 Likes

Would the script look like this?

2 Likes

Yes that’s better, all you have to do now is change the line 5 to

player.PlayerAdded:Connect(function(player)

Also one tip: you should use 1 datastore for all the values, but let’s keep it that way for now.

Edit: You might wanna check for both value names, I’ve noticed you’re trying to access it by using points and Points.

3 Likes

Ok, I got the game updated with the new script, but the data is still not saving. There are no errors in studio when I run the game. I’m still learning how to script , so are there any obvious errors that I am missing? The script is in server script service. Should it be in there?

2 Likes

Where is your script located and what type of script is it (local or regular)?

2 Likes

It is a regular script and it is located in server script service.

2 Likes

Oh okay. If you run the game and press F9 key, developer console should appear; can you see any errors in there?

2 Likes

Should my points and rebirths appear in the datastores tab because they are not. There are no errors

2 Likes


If you go under Log → Server, you should see the errors, if there are any of course

2 Likes

No errors are appearing. On my script should all my variable go under the player added because the data store one is not

2 Likes

Could you try adding in a bunch of print statements to your code, show it to me and tell me which of them print out in the output?

2 Likes

Ok. here are the print statements and which one didn’t get printed. You can’t see all the code in this picture but all the prints that weren’t printed are there

2 Likes

Okay so for some reason your data isn’t saving, consequently “If pointsdata Successful” isn’t printing. May I see a screenshot of leaderstats folder in explorer while you’re in game?

2 Likes

Ok, this is the leaderstats folder in the playerDataStore - Roblox Studio 3_21_2020 12_43_11 PM

2 Likes

Yeah that’s the issue, you’re trying to access it as leaderstats.points instead of leaderstats.Points, same goes for Rebirths.
(There’s the same issue in line 8 from what I can see btw)

2 Likes

Oh ok. I look over things easily somtimes

2 Likes

Ok, I added this to the script but it still isn’t printing. The values are defined in the player added function. Does this mean that they are not defined for the rest of the script do I need to define them again?

2 Likes