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.
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.
Ok, how would I get my player leaderstats folder as a variable. The folder saves to each player.
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)
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
.
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?
Where is your script located and what type of script is it (local or regular)?
It is a regular script and it is located in server script service.
Oh okay. If you run the game and press F9 key, developer console should appear; can you see any errors in there?
Should my points and rebirths appear in the datastores tab because they are not. There are no errors
No errors are appearing. On my script should all my variable go under the player added because the data store one is not
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?
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
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?
Ok, this is the leaderstats folder in the player
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)
Oh ok. I look over things easily somtimes
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?