local DataStore = game:GetService("DataStoreService")
local MyData = DataStore:GetDataStore("MyData2")

game.Players.PlayerAdded:Connect(function(player)
	local Folder = Instance.new("Folder")
	Folder.Name = "Stats"
	Folder.Parent = player
	
	local Speed = Instance.new("IntValue")
	Speed.Name = "Speed"
	Speed.Parent = Folder
	
	
	
	
	local Strength = Instance.new("IntValue")
	Strength.Name = "Strength"
	Strength.Parent = Folder
	
	local Stamina = Instance.new("IntValue")
	Stamina.Name = "Stamina"
	Stamina.Parent = Folder
	Stamina.Value = 100
	
	local playerUserId = "Player_"..player.UserId

	
	local data
	local success, errormessage = pcall(function()
	 data = MyData:GetAsync(playerUserId)
	end)
	
	if success then
		if data then
		Strength.Value = data.Strength
		Speed.Value = data.Speed
			end
			end
	
end)


game.Players.PlayerRemoving:Connect(function(player)
	local data = {
		
		Strength = player.Stats.Strength.Value;
		Speed = player.Stats.Speed.Value
	}
	local playerUserId = "Player_"..player.UserId
	local success, errormessage = pcall(function()
		MyData:SetAsync(playerUserId, data)
	end)
	
	if success then
		print("data saved")
	else
		print("error")
	end
	end)

1 comment

0

are you kicking the player to remove them? Assuming this is done in studio