Datastore not saving data

So I’ve created this datastore following a tutorial. I’ve never done datastores with tables before and for some odd reason it doesn’t work. I don’t get any errors in studio or in game but nothing saves. I’ve tried changing values locally in studio and on the server side in studio. I’ve also changed values in game using the /console but things just don’t seem to save. Any suggestions as to why this might be would be very helpful.

EDIT: This is a normal script in ServerScriptService



game.Players.PlayerAdded:Connect(function(player)
	local PlayerGui = player:WaitForChild("PlayerGui")
	local NPCS = PlayerGui:WaitForChild("NPCS")
	local JohnValues = NPCS.John:WaitForChild("Values")
	local JohnCurrentQuest = JohnValues.CurrentQuest -- This is an Int Value
	local JohnCurrentTalkLine = JohnValues.CurrentTalkLine -- This is an Int Value
	local ActiveQuest = JohnValues.ActiveQuest -- This is a Bool value
	
	local NPCStats = NPCData:GetAsync(player.UserId)
	
	if NPCStats ~= nil then
		JohnCurrentQuest.Value = NPCStats[1]
		JohnCurrentTalkLine.Value = NPCStats[2]
		ActiveQuest.Value = NPCStats[3]
	else
		JohnCurrentQuest.Value = 0
		JohnCurrentTalkLine = 0
		ActiveQuest.Value = false
	end
end)



game.Players.PlayerRemoving:Connect(function(player)
	local PlayerGui = player:WaitForChild("PlayerGui")
	local NPCS = PlayerGui:WaitForChild("NPCS")
	local JohnValues = NPCS.John:WaitForChild("Values")
	local JohnCurrentQuest = JohnValues.CurrentQuest -- This is an Int Value
	local JohnCurrentTalkLine = JohnValues.CurrentTalkLine -- This is an Int Value
	local ActiveQuest = JohnValues.ActiveQuest -- This is a Bool value
	
	local NPCSave = {}
	
	table.insert(NPCSave, JohnCurrentQuest.Value)
	table.insert(NPCSave, JohnCurrentTalkLine.Value)
	table.insert(NPCSave, ActiveQuest.Value)
	
	
	NPCData:SetAsync(player.UserId, NPCSave)
end)

There is no SetAsync or UpdateAsync in your code, so it is sending no data change requests to the data store.

1 Like

At the very end when they leave it does NPCData:SetAsync(player.UserId, NPCSave

Any errors in the output when the code runs?

Are you testing this in studio or in a game server?
If you’re in studio, make sure Enable Studio Access to API Servers is enabled via your game settings.

There are no errors when joining or leaving or midway.

I’ve tried both and neither one saves the data. Studio Access to API servers is also enabled

Try using pcall to save/load data

1 Like

Try putting

Game:bindtoclose()
Wait(10)
End

In the very end of your code

Without this your game will instantly close when the last player leaves and the script won’t have enough time to save the data

1 Like

I believe there has been a recent DataStore issue with Roblox’s servers. Apparently in that case, it was kicking the players before they could have their data overwritten. Not exactly sure if that would apply to your case.

Your code looks good so maybe it is some other interference outside of your code.

1 Like