I am trying to make a obby, but it wouldn't save, and I know that because after a lot of looking at the datastore editor and debugging using print. Here's my code:

local service = game:GetService("DataStoreService")
local datastore = service:GetDataStore("StageData") -- Do NOT touch "StageData" or ALL data will be erased.

game.Players.PlayerAdded:Connect(function(player)
	
	local data
	
	local y,n = pcall(function()
		data = datastore:GetAsync(player.UserId.."-stage")
	end)
	
	if y then
		if data then
			player.Team = game.Teams[data]
		end
	else
		print("Something went wrong, reseting progress..")
		warn(n)
		player.Team = game.Teams["Stage 1"]
	end
	
	player:LoadCharacter()
	
end)

game.Players.PlayerRemoving:Connect(function(player)

	local y,n = pcall(function()
		datastore:SetAsync(player.UserId.."-stage",player.Team.Name)
	end)
	
	if y then
		print("All went well, saved with value of "..player.Team.Name)
	elseif n then
		print("Something went wrong")
		warn(n)
	end
	
end)

2 comments

0

some times it doesn't save. That may be your issue

0

I've tried many times.