Still have questions? Join our Discord server and get real time help.
Log in to vote

My leaderstats script is not working properly?

Asked by 4 years ago
Edited 4 years ago

It says line:76 attempt to index local 'PlayersFolder' (a nil value)

and also when the player leaves the folder doesnt delete or go it stays in the server

Additional Info: The stats script is in Workspace and I make the players stats folder go in ServerStorage

local DataStore = game:GetService("DataStoreService"):GetDataStore("OnePieceUltimateTreasurePreAlpha")

    local PlayerStats ="Folder", game.ServerStorage)
    PlayerStats.Name = plr.Name
    local Level ="IntValue", PlayerStats)
    Level.Name = "Level"
    Level.Value = 1
    local LevelEXP ="IntValue", PlayerStats)
    LevelEXP.Name = "LevelEXP"
    LevelEXP.Value = 0
    local Melee ="IntValue", PlayerStats)
    Melee.Name = "Melee"
    Melee.Value = 1
    local MeleeEXP ="IntValue", PlayerStats)
    MeleeEXP.Name = "MeleeEXP"
    MeleeEXP.Value = 0
    local Sword ="IntValue", PlayerStats)
    Sword.Name = "Sword"
    Sword.Value = 1
    local SwordEXP ="IntValue", PlayerStats)
    SwordEXP.Name = "SwordEXP"
    SwordEXP.Value = 0
    local Sniper ="IntValue", PlayerStats)
    Sniper.Name = "Sniper"
    Sniper.Value = 1
    local SniperEXP ="IntValue", PlayerStats)
    SniperEXP.Name = "SniperEXP"
    SniperEXP.Value = 0
    local Armament ="IntValue", PlayerStats)
    Armament.Name = "Armament"
    Armament.Value = 0
    local ArmamentEXP ="IntValue", PlayerStats)
    ArmamentEXP.Name = "ArmamentEXP"
    ArmamentEXP.Value = 0
    local Conqueror ="IntValue", PlayerStats)
    Conqueror.Name = "Conqueror"
    Conqueror.Value = 0
    local ConquerorEXP ="IntValue", PlayerStats)
    ConquerorEXP.Name = "ConquerorEXP"
    ConquerorEXP.Value = 20
    local Berry ="IntValue", PlayerStats)
    Berry.Name = "Berry"
    Berry.Value = 1

    local specialkey = "player-"..plr.userId

    local GetSaved = DataStore:GetAsync(specialkey)

    if GetSaved then
        Level.Value = GetSaved[1]
        LevelEXP.Value = GetSaved[2]
        Melee.Value = GetSaved[3]
        MeleeEXP.Value = GetSaved[4]
        Sword.Value = GetSaved[5]
        SwordEXP.Value = GetSaved[6]
        Sniper.Value = GetSaved[7]
        SniperEXP.Value = GetSaved[8]
        Armament.Value = GetSaved[9]
        ArmamentEXP.Value = GetSaved[10]
        Conqueror.Value = GetSaved[11]
        ConquerorEXP.Value = GetSaved[12]
        Berry.Value = GetSaved[13]
        local ForSaving = {Level.Value, LevelEXP.Value, Melee.Value, MeleeEXP.Value, Sword.Value, SwordEXP.Value, Sniper.Value, SniperEXP.Value, Armament.Value, ArmamentEXP.Value, Conqueror.Value, ConquerorEXP.Value, Berry.Value}
        DataStore:SetAsync(specialkey, ForSaving)


    local PlayersFolder = game.ServerStorage:FindFirstChild(plr.Name)
    local specialkey = "player-"..plr.userId
    local SaveTable = {PlayersFolder.Level.Value, PlayersFolder.LevelEXP.Value, PlayersFolder.Melee.Value, PlayersFolder.MeleeEXP.Value, PlayersFolder.Sword.Value, PlayersFolder.SwordEXP.Value, PlayersFolder.Sniper.Value, PlayersFolder.SniperEXP.Value, PlayersFolder.Armament.Value, PlayersFolder.ArmamentEXP.Value, PlayersFolder.Conqueror.Value, PlayersFolder.ConquerorEXP.Value, PlayersFolder.Berry.Value}
    DataStore:SetAsync(specialkey, SaveTable)

1 answer

Log in to vote
Answered by 4 years ago
Edited 4 years ago

For starters, the reason the player's folder doesn't remove is because you never made it remove when they leave.

You'll need to add:


Right before end when they're leaving.

As for the main issue, no idea, sorry.


Found out the issue!

Since in studio, it is still there, you need to add a wait() at the beginning of the anon. function, to show that they're not equal in times of running. I don't know any other way to explain it, but add wait() first.


Answer this question