# Usage Examples

### **Example Usage**

```lua
local DataHandler = require(108002867325509)

-- Update the configuration with the desired values
DataHandler.Config.DataStoreName = "PlayerData_v1"
DataHandler.Config.Keys = {"stats"}

game.Players.PlayerAdded:Connect(function(player)
	-- Create leader stats for the player
	DataHandler:CreateLeaderStats(player, {
		["Cash"] = "NumberValue",
		["Level"] = "NumberValue"
	})

	-- Load player data from DataStore
	local playerData = DataHandler:LoadData(player.UserId, "stats")
	if playerData then
		-- Apply loaded values to leader stats
		if playerData.Cash then
			player.leaderstats.Cash.Value = playerData.Cash
		end
		if playerData.Level then
			player.leaderstats.Level.Value = playerData.Level
		end
	else
		-- If no data is found, set default values
		player.leaderstats.Cash.Value = 0
		player.leaderstats.Level.Value = 0
	end

	-- Every second, player will get +1 on both stats
	while wait(1) do
		player.leaderstats.Cash.Value += 1
		player.leaderstats.Level.Value += 1
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	-- Save data when player leaves
	DataHandler:SaveData(player, "stats", {
		Cash = player.leaderstats.Cash.Value,
		Level = player.leaderstats.Level.Value
	})
end)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kno.gitbook.io/ezmodules/data-handler/usage-examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
