Here is the script:
-- Define variables
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
-- You should put your data store as a separate variable then the service one
local DataStore = DataStoreService:GetDataStore("NameHere")
-- Loads the data back to the player
game.Players.PlayerAdded:Connect(function(player)
-- Creates the stats
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local points = Instance.new("IntValue")
points.Name = "Points"
points.Parent = leaderstats
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Parent = leaderstats
local Key = "player-"..player.UserId -- key
pcall(function() -- Stops errors
-- Data Stores can error so thats why I did this
SavedStats = DataStore:GetAsync(Key)
end)
-- Gives the player the data if they have data else create a datastore for them
if SavedStats then
points.Value = SavedStats[1]
coins.Value = SavedStats[2]
else
local Values = {
points.Value;
coins.Value
}
pcall(function() -- Stops errors
DataStore:SetAsync(Key, Values)
end)
end
Key = "player-"..player.UserId
valuesToSave = {
player.leaderstats.Points.Value;
player.leaderstats.Coins.Value}
pcall(function() -- Stops errors
DataStore:SetAsync(Key, valuesToSave)
end)
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
DataStore:SetAsync(Key, valuesToSave)
end)
end)
end)
Thanks for the help!

3 comments
When using pcalls, you have to return a value in the function to see if it ran correctly or not.
How? Where should I place the argument?
Here wait a second, I'll make an answer.