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

My leaderstats script is not working properly?

Asked by 4 years ago

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

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

game.Players.PlayerAdded:connect(function(plr)
    local PlayerStats = Instance.new("Folder", game.ServerStorage)
    PlayerStats.Name = plr.Name
    local Level = Instance.new("IntValue", PlayerStats)
    Level.Name = "Level"
    Level.Value = 1
    local LevelEXP = Instance.new("IntValue", PlayerStats)
    LevelEXP.Name = "LevelEXP"
    LevelEXP.Value = 0
    local Melee = Instance.new("IntValue", PlayerStats)
    Melee.Name = "Melee"
    Melee.Value = 1
    local MeleeEXP = Instance.new("IntValue", PlayerStats)
    MeleeEXP.Name = "MeleeEXP"
    MeleeEXP.Value = 0
    local Sword = Instance.new("IntValue", PlayerStats)
    Sword.Name = "Sword"
    Sword.Value = 1
    local SwordEXP = Instance.new("IntValue", PlayerStats)
    SwordEXP.Name = "SwordEXP"
    SwordEXP.Value = 0
    local Sniper = Instance.new("IntValue", PlayerStats)
    Sniper.Name = "Sniper"
    Sniper.Value = 1
    local SniperEXP = Instance.new("IntValue", PlayerStats)
    SniperEXP.Name = "SniperEXP"
    SniperEXP.Value = 0
    local Armament = Instance.new("IntValue", PlayerStats)
    Armament.Name = "Armament"
    Armament.Value = 0
    local ArmamentEXP = Instance.new("IntValue", PlayerStats)
    ArmamentEXP.Name = "ArmamentEXP"
    ArmamentEXP.Value = 0
    local Conqueror = Instance.new("IntValue", PlayerStats)
    Conqueror.Name = "Conqueror"
    Conqueror.Value = 0
    local ConquerorEXP = Instance.new("IntValue", PlayerStats)
    ConquerorEXP.Name = "ConquerorEXP"
    ConquerorEXP.Value = 20
    local Berry = Instance.new("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]
    else
        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)

    end
end)


game.Players.PlayerRemoving:connect(function(plr)
    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)
end)
0
does the folder also get removed when the player leaves? patrline5599 150 — 4y
0
Nope XxSHjokerxX 18 — 4y

Answer this question