" 12:43:55.808 - BindToClose failed because the model is already being closed."
local bindableEvent = Instance.new("BindableEvent")
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
dataStores:SetAsync(player.UserId.."-Bucks",player.leaderstats.Bucks.Value)
print ("Saved")
playersLeft = playersLeft - 1
bindableEvent:Fire()
end)
game:BindToClose(function()
--Upon shutdown, this will be triggered
while playersLeft > 0 do
bindableEvent.Event:Wait()
end
end)
end)
