How can i modify this script so it saves when i leave the game?
function newPlayer(player)
local stats = Instance.new("Folder",player)
stats.Name = "leaderstats"
local points = Instance.new("IntValue")
points.Name = "Points"
points.Value = 0
local survivals = Instance.new("IntValue")
survivals.Name = "Survivals"
survivals.Value = 0
points.Parent = stats
survivals.Parent = stats
stats.Parent = player
end
game.Players.ChildAdded:connect(newPlayer)
bin.running.Changed:connect(function () runningChanged(bin.running) end)
print("Leaderboard Loaded")

2 comments
I am not aware of exactly how to do it, but I am certain that you use DataStoreService for this. For more information on DataStoreService you may go to YouTube and see what is or you can go to the Developer Hub and check some information about it: https://developer.roblox.com/en-us
Oh and by the way...game.Players.PlayerAdded is recommended for this event. When wanting to save the data use game.Players.PlayerRemoving so that you can tell the server the user hates the game and leaves it.