local DataStoreService = game:GetService("DataStoreService")

local MyDataStore = DataStoreService:GetDataStore("DataStore")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder",player)
	leaderstats.Name = "leaderstats"
	
	local Cash = Instance.new("NumberValue",leaderstats)
	Cash.Name = "Cash"
	
	local Stand = Instance.new("StringValue",leaderstats)
	Stand.Name = "Stand"
	
	local data
	local Success,Errormessage = pcall(function()
	data = MyDataStore:GetAsync(player.UserId.."-Cash",player.UserId.."-Stand") 
end)
	if Success then
		Cash.Value = data 
	else
			print("Error Getting Ur Data")
			warn(Errormessage)
		end
	end)
	



game.Players.PlayerRemoving:Connect(function(player)
	local Success , ErrorMessage = pcall(function()
		MyDataStore:SetAsync(player.UserId.."-Cash",player.leaderstats.Cash.Value)
		MyDataStore:SetAsync(player.UserId.."-Stand",player.leaderstats.Stand.Value)
end)

if Success then
	print("Players Data Was Saved")
	else 
		print("There was a error loading the data")
		warn(error)
	end
end)
	

1 comment

0

Explain more about the error