The data does not save when the player leaves the server. Why is that?
dss = game:GetService("DataStoreService")
ds = dss:GetDataStore("test123498")
function save(player)
local playerId = "Player_"..player.UserId
local tries = 0
local success
repeat
tries = tries + 1
success = pcall(function()
ds:SetAsync(playerId, 221321)
end)
if not success then wait(1) end
until tries == 3 or success
if not success then
warn("Cannot save data for player!")
end
end
function load(player)
local playerId = "Player_"..player.UserId
local data = ds:GetAsync(playerId)
if data == 1 then
game.Workspace.Model:Destroy()
end
end
game.Players.PlayerRemoving:Connect(save)
game.Players.PlayerAdded:Connect(load)
