Really confused as to why it does not work. If anyone could help me it is greatly appreciated!
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("BanSystem158192575215")
game.Players.PlayerAdded:Connect(function(plr)
local Data
local Player_ID = "Player_" .. plr.UserId
local Success, err = pcall(function()
Data = DataStore:GetAsync(Player_ID)
end)
if not Data then
Data = {
BanWave = false,
Banned = false,
Unbanned = false,
LastLogged = os.time()
}
end
print(Data) -- Prints Data
end)
game:BindToClose(function()
for i, plr in pairs(game.Players:GetPlayers()) do
local Data
local Player_ID = "Player_" .. plr.UserId
local Success, err = pcall(function()
Data = DataStore:GetAsync(Player_ID)
end)
Data.LastLogged = os.time()
local success,err = pcall(DataStore.UpdateAsync, DataStore, "Player_"..plr.UserId, function()
return Data
end)
print(Data) -- Prints Nil
if not success then error(err) end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local Data
local Player_ID = "Player_" .. plr.UserId
local Success, err = pcall(function()
Data = DataStore:GetAsync(Player_ID)
end)
Data.LastLogged = os.time()
local success,err = pcall(DataStore.UpdateAsync, DataStore, "Player_"..plr.UserId, function()
return Data
end)
print(Data) -- Prints Nil
if not success then error(err) end
end)
Output: