Hello, I am currently experiencing a problem with my script for the datasave. In fact the script works for some people, sometimes it bugs and resets for others people. Does anyone see a problem with my script? Thank you
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("Creatures3")
game.Players.PlayerAdded:Connect(function(plr)
local folder = Instance.new("Folder")
folder.Name = "Creatures"
folder.Parent = plr
local data
local success, errorMsg = pcall(function()
data = DataStore:GetAsync("CreatureData-"..plr.UserId)
end)
if success and data then
for i,cName in pairs(data) do
if workspace.Creatures:FindFirstChild(cName) then
local newval = Instance.new("BoolValue")
newval.Name = cName
newval.Parent = folder
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local cTable = {}
for i, creature in pairs(plr:WaitForChild("Creatures"):GetChildren()) do
table.insert(cTable,creature.Name)
end
local success, errorMsg = pcall(function()
DataStore:SetAsync("CreatureData-"..plr.UserId,cTable)
end)
end)
game:BindToClose(function()
for i, plr in pairs(game.Players:GetChilden()) do
local cTable = {}
for i, creature in pairs(plr:WaitForChild("Creatures"):GetChildren()) do
table.insert(cTable,creature.Name)
end
local success, errorMsg = pcall(function()
DataStore:SetAsync("CreatureData-"..plr.UserId,cTable)
end)
end
end)