Help with Obby Save Data Leaderstats

so my save data leaderstats script works. but not for one of my friends (hes the owner) any help?

local dss = game:GetService("DataStoreService")
local ss = dss:GetDataStore("PlayerStageDataStore")

function plrToStage(plr)
	repeat wait() until plr.Character.HumanoidRootPart
	
	local sp = game.Workspace.Checkpoints:FindFirstChild(tostring(plr.leaderstats.Stage.Value))
	
	plr.Character.HumanoidRootPart.CFrame = sp.CFrame + Vector3.new(0,2.5,0)
end
game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local stage = Instance.new("IntValue")
	stage.Name = "Stage"
	stage.Parent = leaderstats
	
	local success, errorMsg = pcall(function()
		stage.Value = ss:GetAsync(player.UserId)
	end)
	
	if success then
		print("Got "..player.Name.."'s Data.")
	else
		warn(errorMsg)
	end
	
	player.CharacterAdded:Connect(function()
		plrToStage(player)
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	local success, errorMsg = pcall(function()
		ss:SetAsync(player.UserId,player.leaderstats.Stage.Value)
	end)
	
	if success then
		print("Saved "..player.Name.."'s Data.")
	end
end)

for _, checkpoint in pairs(game.Workspace.Checkpoints:GetChildren()) do
	checkpoint.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			
			local cn = tonumber(checkpoint.Name)
			
			if player.leaderstats.Stage.Value < cn then
				player.leaderstats.Stage.Value = cn
			end
		end
	end)
end
2 Likes

Is the StageValue the only thing you save when leaving the game? Because after your code the DataStoreKey is just the users playerID. Maybe you save something else in another script and your friends datastore was saving something else?

To avoid this I recommend setting a unique DataStoreKey.

For example instead of saying:

ss:SetAsync(player.UserId,player.leaderstats.Stage.Value)

I recommend to say:

ss:SetAsync("Stages_"..player.UserId,player.leaderstats.Stage.Value)

Do the same when using “GetAsync”

If the problem persists or that was not the problem from the beginning, I would be clueless on why it would work with you but not with him.
If so try:

  • Troubleshooting
  • Saving the place to ROBLOX
  • Publishing the place

If that doesn’t help, I’m not exactly sure what’s going on.

somehow, trying to make a reset data button (and failing). It worked!

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