Sungmingamerpro13

UnusedContentDataStore

Aug 31st, 2025
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 1.85 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2. local UnusedContentDataStore = game:GetService("DataStoreService"):GetDataStore("UnusedContent")
  3.  
  4. game.Players.PlayerAdded:Connect(function(player)
  5.     local previousData = UnusedContentDataStore:GetAsync(player.UserId)
  6.     local UnusedContent
  7.    
  8.     if UnusedContent ~= nil then
  9.         UnusedContent = previousData
  10.     else
  11.         UnusedContent = script.UnusedContent.Value
  12.         UnusedContentDataStore:SetAsync(player.UserId, UnusedContent)
  13.     end
  14.    
  15.     local UnusedContentValue = Instance.new("StringValue", player)
  16.     UnusedContentValue.Name = "UnusedContent"
  17.     UnusedContentValue.Value = UnusedContent
  18.    
  19.     player.UnusedContent.Value = "On"
  20.    
  21.     if player.UnusedContent.Value == "On" then
  22.         player.PlayerGui:WaitForChild("DeathScreen").Early_DeathScreen.Disabled = false
  23.         player.PlayerGui:WaitForChild("DeathScreen").Final_DeathScreen.Disabled = true
  24.         player.PlayerGui:WaitForChild("DeathScreen").DeathFrame.DiedFrame.Lives.Visible = true
  25.     else
  26.         player.PlayerGui:WaitForChild("DeathScreen").Early_DeathScreen.Disabled = true
  27.         player.PlayerGui:WaitForChild("DeathScreen").Final_DeathScreen.Disabled = false
  28.         player.PlayerGui:WaitForChild("DeathScreen").DeathFrame.DiedFrame.Lives.Visible = false
  29.     end
  30.    
  31. end)
  32.  
  33. game:BindToClose(function()
  34.     print("STOPPED!")
  35.  
  36.     for i,player in pairs(game.Players:GetPlayers()) do
  37.         local value = player.UnusedContent.Value
  38.         UnusedContentDataStore:SetAsync(player.UserId, value)
  39.         print("Saved data for "..player.Name)
  40.     end
  41. end)
  42.  
  43. game.Players.PlayerRemoving:Connect(function(player)
  44.     local value = player.UnusedContent.Value
  45.  
  46.     if value ~= nil then
  47.         print("Found data to save for "..player.Name.."!")
  48.         UnusedContentDataStore:SetAsync(player.UserId, value)
  49.         print("Saved data for "..player.Name)
  50.     else
  51.         print("Did not manage to find data to save for "..player.Name.."!")
  52.     end
  53. end)
  54.  
Advertisement
Add Comment
Please, Sign In to add comment