Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[DATA SAVING] Arrests and Arrested both save, but not the team that the player was on?

Asked by
Vlym 19
2 years ago
game.Players.PlayerAdded:Connect(function(plr)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = plr

    local arrests = Instance.new("IntValue")
    arrests.Value = 0
    arrests.Name = "Arrests"
    arrests.Parent = leaderstats

    local arrested = Instance.new("IntValue")
    arrested.Value = 0
    arrested.Name = "Arrested"
    arrested.Parent = leaderstats

    local playerUserId = "Player_"..plr.UserId
    local data = playerData:GetAsync(playerUserId)
    if data then
        arrests.Value = data["Arrests"]
        arrested.Value = data["Arrested"]
        plr.Team = data["Team"]
    else
        arrests.Value = 0
        arrested.Value = 0
    end
end)

local function createTable(player)
    local playerStats = {}
    for i,stat in pairs(player.leaderstats:GetChildren()) do
        playerStats[stat.Name] = stat.Value
    end
    playerStats["Team"] = player.Team
    return playerStats
end

local function onPlayerExit(player)
    local playerStats = createTable(player)
    local success, errorMessage = pcall(function()
        local playerUserId = "Player_"..player.UserId
        playerData:SetAsync(playerUserId,playerStats)
    end)
    if not success then
        warn("error when saving data")
    end
end

game.Players.PlayerRemoving:Connect(onPlayerExit)
0
can you be more specific on what is happening? raid6n 2196 — 2y

Answer this question