Hello everybody! I encountered this problem for the first time “invalid argument #1 to ‘pairs’ (table expected, got nil)”, what’s wrong?
local Dss = game:GetService("DataStoreService"):GetDataStore("TESTNUMBERTHREE")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = player
leaderstats.Name = "leaderstats"
local Tools = Instance.new("Folder")
Tools.Parent = player
Tools.Name = "Tools"
local Sharpening = Instance.new("IntValue")
Sharpening.Parent = leaderstats
Sharpening.Name = "Sharpening"
Sharpening.Value = 0
local Rebirth = Instance.new("IntValue")
Rebirth.Parent = leaderstats
Rebirth.Name = "Rebirth"
Rebirth.Value = 0
local OwnedTools = Instance.new("Folder")
OwnedTools.Parent = Tools
OwnedTools.Name = "OwnedTools"
local OwndTool = Instance.new("StringValue")
OwndTool.Parent = OwnedTools
local SharpeningUpgrd = Instance.new("StringValue")
SharpeningUpgrd.Parent = Tools
SharpeningUpgrd.Name = "SharpeningUpgrd"
SharpeningUpgrd.Value = "Stone"
local Money = Instance.new("IntValue")
Money.Parent = leaderstats
Money.Name = "Money"
local EquipKnife = Instance.new("StringValue", player)
EquipKnife.Name = "EquipKnife"
EquipKnife.Value = ""
local OwnedKnife = Instance.new("Folder", player)
OwnedKnife.Name = "OwnedKnife"
local RebirthMulti= Instance.new("IntValue",leaderstats)
RebirthMulti.Name = "RebirthMulti"
RebirthMulti.Value =1
game:GetService("ReplicatedStorage"):WaitForChild("Tools"):FindFirstChild("WoodKnife"):Clone().Parent = OwnedKnife
local GetData = Dss:GetAsync("id_" .. player.UserId)
local OwnedKnifeTable = {}
if GetData then
EquipKnife.Value = GetData[5]
RebirthMulti.Value = GetData[9]
Rebirth.Value = GetData[10]
Money.Value = GetData[11]
Sharpening.Value = GetData[12]
OwnedKnifeTable = GetData[13]
else
local TableData = {
EquipKnife.Value,
RebirthMulti.Value,
Rebirth.Value ,
Money.Value,
Sharpening.Value,
OwnedKnifeTable ,
}
Dss:GetAsync("id_" .. player.UserId,TableData)
end
for i ,v in pairs(OwnedKnifeTable) do
local NewKnife= game.ReplicatedStorage.Tools:FindFirstChild(tostring(v)):Clone()
NewKnife.Parent= OwnedKnifeTable
end
player.Backpack:ClearAllChildren()
if EquipKnife.Value ~= "" then
local KnifeSelect= game.ReplicatedStorage.Tools:FindFirstChild(EquipKnife.Value):Clone()
KnifeSelect.Parent = player.Backpack
end
game.Players.PlayerRemoving:Connect(function(plr)
local OwnedKnifeTable = {}
for i ,v in pairs(plr.OwnedKnife:GetChildren()) do
if v.Name == "WoodKnife" then
else
table.insert(OwnedKnifeTable,v.Name)
end
end
Dss:SetAsync("id_" .. plr.UserId,{
plr.EquipKnife.Value,
plr.leaderstats.RebirthMulti.Value,
plr.leaderstats.Rebirth.Value ,
plr.leaderstats.Money.Value,
plr.leaderstats.Sharpening.Value,
OwnedKnifeTable,
})
end)
This is exactly the problem "ServerScriptService.leaderstats:154: invalid argument #1 to ‘pairs’ (table expected, got nil) "
If you need any more information to solve the problem, I will provide it
(I will put away the notes now)