Data Store code not working, please help

I’m trying to make data store for my obby game so that when a player lands on a checkpoint and leave the game, they rejoin on the same checkpoint they landed on before leaving.

I can’t figure out what I did wrong so that my code doesn’t save the data like how it should, when I join and get to a checkpoint then leave to rejoin, it just spawns me right back to the first stage and I still lose my progress. I’m following this scripting tutorial by AlvinBlox - Saving Obby Checkpoints - Roblox Scripting Tutorial - YouTube

I’ve rechecked my code countless times and tried to use the free Data Editor plugin but the plugin wont work while in the game and my code won’t work either even though I’ve skimmed through it and it seems to be identical to AlvinBlox’s code.

Here’s my code.

local DataStoreService = game:GetService("DataStoreService")

local DataStore = DataStoreService:GetDataStore("ObbyDataStore")

game.Players.PlayerAdded:Connect(function(player)
	
	local data
	
	local success, errorMessage = pcall (function()
		data = DataStore:GetAsync(player.UserId.."-stage,")
	end)
	
	if success then
		print("Success")
		if data then
			player.Team = game.Teams[data]
		else
			player.Team = game.Teams.Stage1
		end
	else
		player.Team = game.Teams.Stage1
	end
	
	player:LoadCharacter()
	
end)

game.Players.PlayerRemoving:Connect(function(player)
	
	local teamName = player.Team.Name
	
	local success, errorMessage = pcall (function()
		DataStore:SetAsync(player.UserId.."-stage,teamName")
	end)
	
	if success then
		print("All went well")
	else
		print(errorMessage)
	end
	
end)

You’re putting a whole string together instead of 2 parameters. Consider changing the line to DataStore:SetAsync(player.UserId.."-stage", teamName) and remove the , from the GetAsync function (player.UserId.."-stage")

In the other hand I recommend the use of BindToClose to prevent data lossing and at pcall statements there’s no need for two statements, you could just use and connector.

1 Like

This problem is happening to me too. I tried using free models and looked up videos I think it might be roblox is down on dataStore.

i think the first parameter in setting the data must be only the player’s id and not adding any strings on it
and even in getting the data

Thank you so much for catching that! I also messed up on
data = DataStore:GetAsync(player.UserId…"-stage,")
and put a comma there for no reason which was what was causing it to not work, gladly I found out what the bug in my code was so I can sleep tonight not constantly thinking about it, thank you for your help!