Hi, I'm trying to make a table that saves the weapons name using datastore2. I added bool values to the folder so I could access the players inventory later in the game. The problem is that this script isn't loading when I played and there was no folder in the player.
local DataStore2 = require(1936396537)
game.Players.PlayerAdded:Connect(function(plr)
print("Player Added")
local dataweap = DataStore2("Weapons",plr)
local fol = Instance.new("Folder")
fol.Parent = plr
fol.Name = "Weapons"
local tbl = {}
print("Folder Added")
if dataweap:Get() ~= nil then
for i,v in pairs(dataweap:Get())do
table.insert(tbl,v)
local tag = Instance.new("BoolValue")
tag.Parent = fol
tag.Name = v
end
else
table.insert(dataweap,"Wooden Bow")
table.insert(tbl,"Wooden Bow")
local tag = Instance.new("BoolValue")
tag.Parent = fol
tag.Name = "Wooden Bow"
table.insert(dataweap,"Wooden Sword")
table.insert(tbl,"Wooden Sword")
local tag = Instance.new("BoolValue")
tag.Parent = fol
tag.Name = "Wooden Sword"
table.insert(dataweap,"Wooden Spear")
table.insert(tbl,"Wooden Spear")
local tag = Instance.new("BoolValue")
tag.Parent = fol
tag.Name = "Wooden Spear"
dataweap:Set(tbl)
end
local function tblupdate(new)
if dataweap:Get() ~= nil then
for i,v in pairs(dataweap:GetChildren())do
print(v)
if game:GetService("ReplicatedStorage").Weapons:FindFirstChild(v) then
if plr.Weapons:FindFirstChild(v)then
else
table.insert(tbl,v)
local tag = Instance.new("BoolValue")
tag.Parent = fol
tag.Name = v
end
else
table.remove(tbl,v)
table.remove(dataweap,v)
end
end
end
dataweap:Set(tbl)
end
dataweap:OnUpdate(tblupdate)
end)
Help please. Thankyou!
