How can I make the HandTo System's Points don't reset when you leave the Game

Greetings Developer, I’m Abd and I’m a Simple Scripter and I also Design UI’s sometimes!
I have a HandTo System Script with Points and I want to make the Points don’t reset when you leave the Game.
Can someone help me, please?

Script:

----------[LEADERSTATS]----------
game.Players.PlayerAdded:Connect(function(Player)
    local leaderstats = Instance.new("IntValue")
    leaderstats.Name = "leaderstats"

    local Points = Instance.new("StringValue")
    Points.Name = "StaffPoints"
    Points.Value = 0

    Points.Parent = leaderstats
    leaderstats.Parent = Player
    
    if Player:GetRankInGroup(6419782) <= 3 then
        Points.Value = "N/A"
    end
end)

----------[SETTINGS]----------

local Settings = {
    Prefix = ":",
    Group = 6419782,
    Rank = 4,
}

function GetWords(Msg,Pattern)
    local Words = {}
    for w in string.gmatch(Msg, Pattern) do
        table.insert(Words,w)
    end
    return Words
end

local ChatFunctions = {
    ["handto"] = function(Words,Player)
            for _,Target in pairs(game.Players:GetPlayers()) do
                if string.find(string.lower(Target.Name),string.lower(Words[2])) then
                    local Tool = Player.Character:FindFirstChildOfClass("Tool")
                    local Human = Player.Character:FindFirstChildOfClass("Humanoid")
                    if Tool and Human then
                        Human:UnequipTools()
                        wait()
                        Tool.Parent = Target.Backpack
                        Player.leaderstats.StaffPoints.Value = Player.leaderstats.StaffPoints.Value + 1
                    end
                end
                wait()
            end
    end,
}

game.Players.PlayerAdded:Connect(function(Player)
    if Player:GetRankInGroup(Settings.Group) >= Settings.Rank then
        Player.Chatted:Connect(function(Message)
            if string.sub(Message,1,1) == Settings.Prefix then
                local Command = GetWords(string.sub(Message,2),"[%w_]+")
                if ChatFunctions[Command[1]] then
                    ChatFunctions[Command[1]](Command,Player)
                end
            end
        end)
    end
end)

Hello!
For this do

local Data = game:GetService("DataStoreService"):GetDataStore("Name of your data store")
game.Players.PlayerAdded:Connect(function(Player)
    local leaderstats = Instance.new("IntValue")
    leaderstats.Name = "leaderstats"

    local Points = Instance.new("StringValue")
    Points.Name = "StaffPoints"
    Points.Value = 0

    Points.Parent = leaderstats
    leaderstats.Parent = Player
    local PlayersData = Data:GetAsync(Player.UserId.."-HandToPoints")
    if Player:GetRankInGroup(6419782) <= 3  and PlayersData == nil then
        Points.Value = "N/A"
   elseif  Player:GetRankInGroup(6419782) >= 3  and PlayersData ~= nil then
     Points.Value = PlayersData
    end
end)
game.Players.PlayerRemoving:Connect(function(player)
Data:SetAsync(player.UserId.."-HandToPoints",player.leaderstats.StaffPoints.Value)
end)

I hope it work!

1 Like

Hi, Thanks for helping but where should I add that and what should I remove?

Replace that with your PlayerAdded event and when you want add point to player
do

Player.leaderstats.StaffPoints.Value = Player.leaderstats.StaffPoints.Value + 1

Okay, Thank you. :sparkling_heart:

Why are you doing points string value do it int value

You should be saving points by using DataStore2. (Alternatively use regular DataStores but these are unreliable.)

I’m doing it String because I can’t type anything like “N/A” by using the int value.

Will this script work? @CAP7A1N

----------[DATASTORE]----------
local Data = game:GetService("DataStoreService"):GetDataStore("Name of your data store")
game.Players.PlayerAdded:Connect(function(Player)
    local leaderstats = Instance.new("IntValue")
    leaderstats.Name = "leaderstats"

    local Points = Instance.new("StringValue")
    Points.Name = "StaffPoints"
    Points.Value = 0

    Points.Parent = leaderstats
    leaderstats.Parent = Player
    local PlayersData = Data:GetAsync(Player.UserId.."-HandToPoints")
    if Player:GetRankInGroup(6419782) <= 3  and PlayersData == nil then
        Points.Value = "N/A"
   elseif  Player:GetRankInGroup(6419782) >= 3  and PlayersData ~= nil then
     Points.Value = PlayersData
    end
end)
game.Players.PlayerRemoving:Connect(function(player)
Data:SetAsync(player.UserId.."-HandToPoints",player.leaderstats.StaffPoints.Value)
end)

----------[LEADERSTATS]----------
game.Players.PlayerAdded:Connect(function(Player)
    local leaderstats = Instance.new("IntValue")
    leaderstats.Name = "leaderstats"

    local Points = Instance.new("StringValue")
    Points.Name = "StaffPoints"
    Points.Value = 0

    Points.Parent = leaderstats
    leaderstats.Parent = Player
    
    if Player:GetRankInGroup(6419782) <= 3 then
        Points.Value = "N/A"
    end
end)

----------[SETTINGS]----------

local Settings = {
    Prefix = ":",
    Group = 6419782,
    Rank = 4,
}

function GetWords(Msg,Pattern)
    local Words = {}
    for w in string.gmatch(Msg, Pattern) do
        table.insert(Words,w)
    end
    return Words
end

local ChatFunctions = {
    ["handto"] = function(Words,Player)
            for _,Target in pairs(game.Players:GetPlayers()) do
                if string.find(string.lower(Target.Name),string.lower(Words[2])) then
                    local Tool = Player.Character:FindFirstChildOfClass("Tool")
                    local Human = Player.Character:FindFirstChildOfClass("Humanoid")
                    if Tool and Human then
                        Human:UnequipTools()
                        wait()
                        Tool.Parent = Target.Backpack
                        Player.leaderstats.StaffPoints.Value = Player.leaderstats.StaffPoints.Value + 1
                    end
                end
                wait()
            end
    end,
}

game.Players.PlayerAdded:Connect(function(Player)
    if Player:GetRankInGroup(Settings.Group) >= Settings.Rank then
        Player.Chatted:Connect(function(Message)
            if string.sub(Message,1,1) == Settings.Prefix then
                local Command = GetWords(string.sub(Message,2),"[%w_]+")
                if ChatFunctions[Command[1]] then
                    ChatFunctions[Command[1]](Command,Player)
                end
            end
        end)
    end
end)

Why are you creating leaderstats twice?

Also, I am not an IDE. While I can quickly look over small scripts and possibly find bugs, you should test it in your game. Then come back here if it doesn’t work.