I need help for a Team system

I need help with this:
I want to make a team system (example) you are in team A when you have 5 points in the leaderstats you go to team B and when you have 10 points you go to team C and so on infinitely.
I also want that when you leave the game and re-enter you stay in the team that you were

Sorry if it is not the right place to do this post but I have been trying script for three days and none works
Thanks.

Post: I need help for a Team system

If you connect a Value.Changed:Connect(function(newVal) event to the value when the leaderstats are set up, you can check to see if they meet the requirements to be on a team. If they do, and aren’t already on the team, you can change it.

To save it use DataStoreService and do something like:

local DSS = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

local TeamDataStore = DSS:GetDataStore("Teams")

Players.PlayerAdded:Connect(function(plr)
    local data
    local success, errormessage = pcall(function()
        data = TeamDataStore:GetAsync(plr.UserId)
    end)

    if success and data then
        local team = Teams:FindFirstChild(data)
        if team then
            plr.Team = team
        else
            warn("Couldn't find team! Did you change the name?")
        end
    elseif success then
        warn("This player has no data!")
        --> put onto default team
    else
        warn("Error while getting player data!")
        warn(errormessage)
    end
end)

Players.PlayerRemoving:Connect(function(plr)
    local success, errormessage = pcall(function()
        TeamDataStore:SetAsync(plr.Team.Name)
    end)

    if success then
        print("Saved player data!")
    else
        warn("Error while saving player data!")
        warn(errormessage)
    end
end)