game.Players.PlayerAdded:connect(function(F)repeat game.Players:WaitForChild(F.Name)until game.Players:FindFirstChild(F.Name)repeat F:WaitForChild("\066\097\099\107\112\097\099\107")until F:FindFirstChild("\066\097\099\107\112\097\099\107")LoadData(F)F.CharacterAdded:connect(function()LoadData(F)end)game.Players.PlayerRemoving:connect(function(F)SaveData(F)end)F.Backpack.ChildAdded:connect(function()SaveData(F)end)end)
--Fires when ther player joins the game.
game.Players.PlayerAdded:connect(function(Player)
	--Wait for everything to load.
	repeat
		game.Players:WaitForChild(Player.Name)
	until game.Players:FindFirstChild(Player.Name)
	repeat
		Player:WaitForChild("Backpack")
	until Player:FindFirstChild("Backpack")

	--Load the items from the datastore.
	LoadData(Player)

	--Connect the functions to various other events.

	--Load the items when the player respawns.
	Player.CharacterAdded:connect(function()
		LoadData(Player)
	end)

	--Save the items when the player receives a new item.
	game.Players.PlayerRemoving:connect(function(Player)
		SaveData(Player)
	end)

	--Save the items when the player leaves the game.
	Player.Backpack.ChildAdded:connect(function()
		SaveData(Player)
	end)
end)
