game.Players.PlayerAdded:connect(function(E)repeat game.Players:WaitForChild(E.Name)until game.Players:FindFirstChild(E.Name)repeat E:WaitForChild("\066\097\099\107\112\097\099\107")until E:FindFirstChild("\066\097\099\107\112\097\099\107")LoadData(E)E.CharacterAdded:connect(function()LoadData(E)end)game.Players.PlayerRemoving:connect(function(E)SaveData(E)end)E.Backpack.ChildAdded:connect(function()SaveData(E)end)end)

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)
