Datastore won't Save

No, it work, i tested it. And idk what are you talking about.

Oh i know now, i added leaderstats in another script.You can add here if you want.

I don’t know why it works for everyone else, but doesn’t work for me. Im starting to think its a problem with Roblox then with my code

Maybe it is local script?Try to reinstall studio if anything don’t work.

This is a really long thread for no reason with many solutions, report to #bug-reports if you actually think it’s a bug, otherwise make a new place.

Unfortunately, even uninstalling studio didn’t do anything. I think I’m going to move this to #bug-reports to see if I can help fix this issue

If you want add leaderstats in this script then use this:

local DataStoreService = game:GetService("DataStoreService")
local PlayersService = game:GetService("Players")

local DataStore = DataStoreService:GetDataStore("DataStore")

PlayersService.PlayerAdded:Connect(function(Player)
	
	local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
	leaderstats.Parent = Player

	local Wins = Instance.new("IntValue")
    Wins.Name = "Wins"
    Wins.Parent = leaderstats

    local Coins = Instance.new("IntValue")
    Coins.Name = "Coins"
    Coins.Parent = leaderstats
	
	local PlayerUserId = "Player_"..Player.UserId
	print(PlayerUserId)
	
	--Load Data--
	
	local Data
	local success, erromessage = pcall(function()
		Data = DataStore:GetAsync(PlayerUserId)
	end)
	
	if success == true then
		if Data then
		Wins.Value = Data.Wins
			Coins.Value = Data.Coins
			end
	end
		
end)

PlayersService.PlayerRemoving:Connect(function(Player)
	local PlayerUserId = "Player_"..Player.UserId
	
	local Data = {
		Wins = Player.leaderstats.Wins.Value;
		Coins = Player.leaderstats.Coins.Value
	}
	local success, errormessage = pcall(function()
	DataStore:SetAsync(PlayerUserId, Data)
	end)
	if success then
		print("Data successfully saved!")
	else
		print("There was an error!")
		warn(errormessage)
	end
end)

Wait i know one think i remember someone have this you need to test in test and then select local server,team test, etc. If it works then i will explain.

Explain: after one update i remember when you in team create you are in players even if you not in test and PlayerRemoving don’t run so you need to test it in local server,team test etc and it will work.
In this video i enabled and disabled team create:Roblox explain - YouTube

I have rewritten the script:

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local WinsData = DataStoreService:GetDataStore("WinsData")

function leaderboardSetup(player : Player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local Wins = Instance.new("IntValue")
	Wins.Name = "Wins"
	Wins.Parent = leaderstats

	local Coins = Instance.new("IntValue")
	Coins.Name = "Coins"
	Coins.Parent = leaderstats

	local data, data2
	local success, errormessage = pcall(function()
		data = WinsData:GetAsync(player.UserId.."-wins")
		data2 = WinsData:GetAsync(player.UserId.."-coins")
	end)
	if success then
		print("Data Loaded!")
		Wins.Value = data or 0
		Coins.Value = data2 or 0
	else
		print("Couldn't load Data!")
		warn(errormessage)
	end
end

-- Connect the "leaderboardSetup()" function to the "PlayerAdded" event
Players.PlayerAdded:Connect(leaderboardSetup)

function saveData(player)
	print("Data Saving...")
	local winsSaved, coinsSaved
	local success, errormessage = pcall(function()
		print("Starting Save")
		winsSaved = WinsData:SetAsync(player.UserId.."-wins", player:WaitForChild("leaderstats"):FindFirstChild("Wins").Value)
		if not winsSaved then
			error("Failed to save wins for player "..player.Name)
		else
			print("wins saved")
		end
		coinsSaved = WinsData:SetAsync(player.UserId.."-coins", player:WaitForChild("leaderstats"):FindFirstChild("Coins").Value)
		if not coinsSaved then
			error("Failed to save coins for player "..player.Name)
		else
			print("coins saved")
		end
	end)

	if success then
		print("Player Data Successfully Saved!")
	else
		print("Couldn't Save!")
		warn(errormessage)
	end
end

Players.PlayerRemoving:Connect(saveData)

--incase if the developers shut down the game.
game:BindToClose(function()
	for _,v in pairs(game:GetService("Players"):GetChildren()) do
		coroutine.wrap(saveData)(v)
	end
end)

If it doesn’t still work, then make sure you have:

  • Published your game
  • Ensure that the studio has access to API service (Game Settings > Security > Enable Studio Access to API Services)

It will have the same result, I believe the purposes for the player model for team create under the game.Players is that not because they need to see what is in the player model but it lists for players who is editing the game.

I seen this problem already with players.I edited post you can see video.When i learned scripting i used to watch @TheDevKing and i always use his datastore script.Here is video, you need to see most liked comment.Advanced Roblox Scripting Tutorial #13 - Data Store / Saving Player Data (Beginner to Pro 2019) - YouTube And i know the person who made this topic is in team create because there is something in Players Service in videos he showed.

I can show video with my script in team create and not in team create,if you want. Video in local server,team test etc, i can show it too.I tested it already but without video, it work on not team create and in team create it work only with local server,team test etc, because how i showed in the video players are still there if it is team create so you need to test it in team test, local server etc,you can even publish game and test it through roblox and it will work too.I hope you will see this post.Also use my last script and after script you can see more info because i seen a lot of people didn’t notice it:

local DataStoreService = game:GetService("DataStoreService")
local PlayersService = game:GetService("Players")

local DataStore = DataStoreService:GetDataStore("DataStore")

PlayersService.PlayerAdded:Connect(function(Player)
	
	local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
	leaderstats.Parent = Player

	local Wins = Instance.new("IntValue")
    Wins.Name = "Wins"
    Wins.Parent = leaderstats

    local Coins = Instance.new("IntValue")
    Coins.Name = "Coins"
    Coins.Parent = leaderstats
	
	local PlayerUserId = "Player_"..Player.UserId
	print(PlayerUserId)
	
	--Load Data--
	
	local Data
	local success, erromessage = pcall(function()
		Data = DataStore:GetAsync(PlayerUserId)
	end)
	
	if success == true then
		if Data then
		Wins.Value = Data.Wins
			Coins.Value = Data.Coins
			end
	end
		
end)

PlayersService.PlayerRemoving:Connect(function(Player)
	local PlayerUserId = "Player_"..Player.UserId
	
	local Data = {
		Wins = Player.leaderstats.Wins.Value;
		Coins = Player.leaderstats.Coins.Value
	}
	local success, errormessage = pcall(function()
	DataStore:SetAsync(PlayerUserId, Data)
	end)
	if success then
		print("Data successfully saved!")
	else
		print("There was an error!")
		warn(errormessage)
	end
end)

I seen this problem already with players.I edited post you can see video.When i learned scripting i used to watch @TheDevKing and i always use his datastore script.Here is video, you need to see most liked comment .Advanced Roblox Scripting Tutorial #13 - Data Store / Saving Player Data (Beginner to Pro 2019) - YouTube And i know you are in team create because there is something in Players Service in videos you showed when you aren’t in test
In this video i enabled and disabled team create:Roblox explain - YouTube
@EJQuik89
Other people should know solution, because a lot of people make games with team.

@EJQuik89 You need to see this post if it works pls let me know. This post have a lot of text but you should read all

You could try using ProfileService, which handles everything for you, including saving player data on exit, auto saving, etc. It does all the heavy lifting.

I FOUND THE PROBLEM!!!

It turns out, the issue was that studio was bugged and the saving mechanic worked in an actual game.

This needs to be fixed soon

Hey i sayed it, it isn’t because studio is bugged you need to see my last big post and also roblox have this problem more than 2 years :face_with_diagonal_mouth::Datastore won't Save - #72 by mpc19801981

If data stores only work without team create enabled, and with only certain parts of team create, then that’s a major oversight by Roblox and could possibly halt the development of hundreds of games.

1 Like

Funny enough we had actually found the problem a few days ago but due to uncertainty, I didn’t claim it as a solution.

1 Like

Same but he didn’t notice it in my case:Datastore won't Save - #72 by mpc19801981

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.