ive been trying to make a tool save system for a game i am making, what im trying right now is to save all the tools to a folder and save that but its coming up with a error: "ServerScriptService.Script:12: attempt to index nil with 'allitems'"
Code:
local datastoreservice = game:GetService("DataStoreService")
local items = datastoreservice:GetDataStore("Items")
local allitems = Instance.new("Folder")
game.Players.PlayerAdded:Connect(function(player)
local id = "Player_"..player.UserId
local data
local success, errormessage = pcall(function()
data = items:GetAsync(id)
end)
if success == true then
for i = 1,data.allitems:GetChildren() do
i.Parent = game.Workspace[game.Players.Name]
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerid = "Player_"..player.UserId
for i = 1,game.Workspace[game.Players.Name]:GetChildren() do
if i:IsA("Tool") then
i.Parent = allitems
end
end
local data = allitems
local success, errormessage = pcall(function()
items:SetAsync(playerid, data)
end)
if success then
print("data saved") --to know if ur data saved
else
print("error") --to know if there was a error
warn(errormessage)
end
end)
Any help would be really appreciated, Thankyou
