local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("CandySave_1")
local serverstorage = game:GetService("ServerStorage")
game.Players.PlayerAdded:Connect(function(player)
local candyFolder = Instance.new("Folder")
candyFolder.Name = player.Name
candyFolder.Parent = serverstorage.PlayerThings
local data
local success, errorMsg = pcall(function()
data = DataStore:GetAsync("CandyData"..player.UserId)
end)
if success and data then
for _, ToolName in pairs(data) do
if serverstorage.PlayerThings[player.Name]:FindFirstChild(ToolName) then
print(ToolName)
local clonedTool = game.ServerStorage.Tools:FindFirstChild(ToolName):Clone()
clonedTool.Parent = game.ServerStorage.PlayerTools:FindFirstChild(player.Name)
--[
--local ToolValue = Instance.new("Tool")
--ToolValue.Name = ToolName
--ToolValue.Parent = serverstorage.PlayerThings[player.Name]
--]
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local candyTable = {}
for _, candy in pairs(serverstorage.PlayerThings[player.Name]:GetChildren()) do
table.insert(candyTable, candy.Name)
print(candy.Name)
end
local success, errorMsg = pcall(function()
DataStore:SetAsync("CandyData"..player.UserId, candyTable)
end)
print("test")
if success then
print("Saved")
else
print(errorMsg)
end
end)
game:BindToClose(function()
for _, player in pairs(game.Players:GetPlayers()) do
local candyTable = {}
for _, candy in pairs(serverstorage.PlayerThings[player.Name]:GetChildren()) do
table.insert(candyTable, candy.Name)
print(candy.Name)
end
local success, errorMsg = pcall(function()
DataStore:SetAsync("CandyData"..player.UserId, candyTable)
end)
if success then print("Saved on BTC for "..player.Name) end
end
end)
DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = CandyData1186752308.
It won’t save please help. It doesn’t add tool when u join back.