So I tried printing at the playerremoving function but nothing works and I dont even know why.
Heres my code
local DataStoreService = game:GetService("DataStoreService")
local StoringDataFile = DataStoreService:GetDataStore("DataFile")
local Players = game:GetService("Players")
local ItemsNumber = 0
local ItemsGlobal = {}
Players.PlayerAdded:Connect(function(LocalPlayer)
--///MakingTheStoringFolder
local DataMainFile = Instance.new("Folder",LocalPlayer)
DataMainFile.Name = "DataMainFile"
if not DataMainFile then
LocalPlayer:Kick("Something went wrong 😐")
end
--//CloningTheItems
local Totaltems = 0
local ItemsTable = {}
for _,Items in pairs(script:WaitForChild("Items"):GetChildren()) do
local FoundItem = Items:Clone()
FoundItem.Parent = DataMainFile
table.insert(ItemsTable,FoundItem)
table.insert(ItemsGlobal,FoundItem)
ItemsNumber += 1
Totaltems += 1
end
warn(Totaltems.." Has been found")
local Information = {}
local Passed,Issue = pcall(function()
local CurrentItemData = 0
for _,GetInformation in pairs(DataMainFile:GetChildren()) do
CurrentItemData += 1
local Data
Data = StoringDataFile:GetAsync(LocalPlayer.UserId.."Information"..CurrentItemData)
table.insert(Information,Data)
end
end)
if Passed then
local CurrentDataNumber = 0
for DataNum = 1,Totaltems do
ItemsTable[DataNum].Value = Information[DataNum]
warn(ItemsTable[DataNum].Value)
end
elseif not Passed then
LocalPlayer:Kick("Something went wrong 😐")
warn(Issue)
end
end)
Players.PlayerRemoving:Connect(function(RemovedPlayer)
local Passed,Issue = pcall(function()
for SavingNum = 1,ItemsNumber do
StoringDataFile:SetAsync(RemovedPlayer.UserId.."Information"..SavingNum,RemovedPlayer.DataMainFile:FindFirstChild(ItemsGlobal[SavingNum]).Value)
warn("Worked")
end
end)
if Passed then
else
RemovedPlayer:Kick("Something went wrong 😐")
end
end)```