Hello, so i just made a datastore script tha was supposed to save some values inside of a folder in the player but the output keeps on saying: ServerScriptService.DataSaving.Script:35: attempt to index nil with 'FindFirstChild
here is my script:
local datastoreservice = game:GetService("DataStoreService")
local mydata = datastoreservice:GetDataStore("firstdatastore")
game.Players.PlayerAdded:Connect(function(player)
local data = mydata:GetAsync(player.UserId.."-test")
if data then
for i, v in pairs(data) do
local savedvalue = Instance.new("StringValue")
savedvalue.Name = v
savedvalue.Parent = player.Areas
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local folder = {}
for i, v in pairs(player:FindFirstChild("Areas"):GetChildren()) do
table.insert(folder,v.Name)
end
local sucess, errormsg = pcall(function()
mydata:SetAsync(player.UserId.."-test", folder)
end)
if sucess then
print("saved!")
else
print("there was an error")
end
end)
game:BindToClose(function(player)
local folder = {}
for i, v in pairs(player:FindFirstChild("Areas"):GetChildren()) do
table.insert(folder,v.Name)
end
local sucess, errormsg = pcall(function()
mydata:SetAsync(player.UserId.."-test", folder)
end)
if sucess then
print("saved!")
else
print("there was an error")
end
end)
Thank you!