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

?ServerScriptService.leaderstats:94: invalid argument #1 to 'pairs' (table expected, got string)

Asked by 3 years ago

Can someone help me? im new in LUA programming this is the script: local RS = game:GetService("ReplicatedStorage") local bags = RS.Bags local Dss = game:GetService("DataStoreService") local DS = Dss:GetDataStore("BackpackDataStore1")

game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder", player) leaderstats.Name = "leaderstats"

local dribbles = Instance.new("NumberValue", leaderstats)
dribbles.Name = "Dribbles"
dribbles.Value = 0

local coins = Instance.new("NumberValue", leaderstats)
coins.Name = "Coins"
coins.Value = 0

-----------------------------------------------------------

local datafolder = Instance.new("Folder", player)
datafolder.Name = "Data"

local rebirthsfolder = Instance.new("Folder", datafolder)
rebirthsfolder.Name = "RebirthsData"

local basketballsfolder = Instance.new("Folder", datafolder)
basketballsfolder.Name = "BasketballsData"

local backpackfolder = Instance.new("Folder", datafolder)
backpackfolder.Name = "BackpackData"    

-----------------------------------------------------------

local ownedbasketballsfolder = Instance.new("Folder", basketballsfolder)
ownedbasketballsfolder.Name = "OwnedBasketballs"

local ownedrebirthsfolder = Instance.new("Folder", rebirthsfolder)
ownedrebirthsfolder.Name = "OwnedRebirths"

local ownedbagsfolder = Instance.new("Folder", backpackfolder)
ownedbagsfolder.Name = "OwnedBags"
-----------------------------------------------------------

local equipedbag = Instance.new("StringValue", backpackfolder)
equipedbag.Name = "EquippedBag"
equipedbag.Value = "StarterBag"

local equippedrebirth = Instance.new("StringValue", rebirthsfolder)
equippedrebirth.Name = "EquippedRebirth"
equippedrebirth.Value = "StarterRebirth"

local equippedbasketball = Instance.new("StringValue", basketballsfolder)
equippedbasketball.Name = "EquippedBasketball"
equippedbasketball.Value = "StarterBasketball"

local Insert = Instance.new("StringValue", ownedbagsfolder)
Insert.Name = "StarterBag"

for i, bag in pairs(bags:GetChildren()) do
    if bag:FindFirstChild("isInfinitebag") then
        bag.bagStorage.Value = math.huge
    end
end


-- Data Stores 

local Key = player.UserId

local dribblesData, coinsData, ownedBagsData, ownedrebirthsData, ownedbasketballsData, equippedBagData, equippedRebirthData , equippedBasketballData

local succ, err = pcall(function()
    dribblesData = DS:GetAsync(Key.."-Dribbles")
    coinsData = DS:GetAsync(Key.."-Coins")

    ownedBagsData = DS:GetAsync(Key.."-OwnedBags")
    equippedBagData = DS:GetAsync(Key.."-Equippedbag")

    ownedrebirthsData = DS:GetAsync(Key.."-OwnedRebirths")
    equippedRebirthData = DS:GetAsync(Key.."-EquippedRebirth")

    ownedbasketballsData = DS:GetAsync(Key.."-OwnedBasketballs")
    equippedBasketballData = DS:GetAsync(Key.."-EquippedBasketball")
end)
if succ then
    if dribblesData then
        dribbles.Value = dribblesData
        if coinsData then
            coins.Value = coinsData
        end
        if ownedBagsData then
            for v, bag in pairs(ownedBagsData) do
                if bag ~= "StarterBag" then
                    local Insert = Instance.new("StringValue", ownedbagsfolder)
                    Insert.Name = bag
                end
            end
        end
        if equippedBagData then
            equipedbag.Value = equippedBagData
        end
    end
end
-------------------------------------------------------------
if ownedrebirthsData then
    for c, reb in pairs(ownedrebirthsData) do
        if reb ~= "StarterRebirth" then
            local Insert2 = Instance.new("StringValue", ownedrebirthsfolder)
            Insert2.Name = reb
        end
    end
end
if equippedRebirthData then
    equippedrebirth.Value = equippedRebirthData
end

------------------------------------------------------------
if ownedbasketballsData then
    for d, bkb in pairs(ownedbasketballsData) do
        if bkb ~= "StarterBag" then
            local Insert3 = Instance.new("StringValue", ownedbasketballsfolder)
            Insert3.Name = bkb
        end
    end
end
if equippedBasketballData then
    equipedbag.Value = equippedBasketballData
end

end)

game.Players.PlayerRemoving:Connect(function(player) local Key = player.UserId

local savedOwnedBags = {}
local savedOwnedRebirths = {}
local savedOwnedBasketballs = {}



local succ, err = pcall(function()
    DS:SetAsync(Key.."-Dribbles",player.leaderstats.Dribbles.Value)
    DS:SetAsync(Key.."-Coins",player.leaderstats.Coins.Value)

    DS:SetAsync(Key.."-OwnedBags",player.Data.BackpackData.EquippedBag.Value)
    DS:SetAsync(Key.."-EquippedBag",player.Data.Dribbles.Value)

    DS:SetAsync(Key.."-OwnedRebirths",player.leaderstats.Coins.Value)
    DS:SetAsync(Key.."-EquippedRebirth",player.Data.BackpackData.EquippedBag.Value)

    DS:SetAsync(Key.."-OwnedBasketballs",player.leaderstats.Coins.Value)
    DS:SetAsync(Key.."-EquippedBasketball",player.Data.BackpackData.EquippedBag.Value)

    for i, n in pairs(player.Data.BackpackData.OwnedBags:GetChildren()) do
        table.insert(savedOwnedBags,n.Name)
    end
    DS:SetAsync(Key.."-OwnedBags",savedOwnedBags)

    for i, v in pairs(player.Data.RebirthsData.OwnedRebirths:GetChildren()) do
        table.insert(savedOwnedRebirths,v.Name)
    end
    DS:SetAsync(Key.."-OwnedRebirths",savedOwnedBags)

    for i, c in pairs(player.Data.BackpackData.OwnedBasketballs:GetChildren()) do
        table.insert(savedOwnedBasketballs,c.Name)
    end
    DS:SetAsync(Key.."-OwnedBasketballs",savedOwnedBags)

end)
if succ then
    print("Success while saving Data!")
else
    print("Something went wrong while saving Data! "..err)
end

end)

what is wrong?

Answer this question