It is printing "Success!" and "Data Loaded" but it isn't actually loading the data.

Code:

local serverStorage = game:GetService("ServerStorage")
local datastore = game:GetService("DataStoreService"):GetDataStore("PlayerSave")

game.Players.PlayerAdded:Connect(function(plr)
	
	local f = Instance.new("Folder")
	f.Name = "leaderstats"
	f.Parent = plr
	
	local steps = Instance.new("NumberValue")
	steps.Name = "Steps"
	steps.Parent = f
	
	local rebirths = Instance.new("IntValue")
	rebirths.Name = "Rebirths"
	rebirths.Parent = f
	
	local races = Instance.new("IntValue")
	races.Name = "Races"
	races.Parent = f
	
	local dataFolder = Instance.new("Folder")
	dataFolder.Name = plr.Name
	dataFolder.Parent = serverStorage.RemoteData
	
	local stepsData, rebirthsData, racesData
	
	local success, errormsg = pcall(function()
		stepsData = datastore:GetAsync("Steps-"..plr.UserId)
		rebirthsData = datastore:GetAsync("Rebirths-"..plr.UserId)
		racesData = datastore:GetAsync("Races-"..plr.UserId)
	end)
	
	if success then
		if stepsData then
			steps.Value = stepsData
			rebirths.Value = rebirthsData
			races.Value = racesData
			print("Data Loaded")
		end
	else
		warn(errormsg)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local success, errormsg = pcall(function()
		datastore:SetAsync("Steps-"..plr.UserId, plr.leaderstats.Steps.Value)
		datastore:SetAsync("Rebirths-"..plr.UserId, plr.leaderstats.Rebirths.Value)
		datastore:SetAsync("Races-"..plr.UserId, plr.leaderstats.Races.Value)
	end)
	
	if success then
		print("Success!")
	else
		warn(errormsg)
	end
end)

3 comments

0

There are no errors in the output either.

1

No no no no no no no no no no no no save tables not 3 times use GetAsync, make a table and save all the values in it, it is much more efficient. I reccomend you going to official devforum, there is a tutorial for data stores.

0

Okay, thanks