Advertisement
Sungmingamerpro13

Titles (Story Game)

Feb 23rd, 2025
238
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 1.18 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2. local SaveTitles = game:GetService("DataStoreService"):GetDataStore("Title")
  3.  
  4. game.Players.PlayerAdded:Connect(function(player)
  5.  
  6.     local PreviousData = SaveTitles:GetAsync(player.UserId)
  7.     local Title
  8.  
  9.     if PreviousData ~= nil then
  10.         Title = PreviousData
  11.     else
  12.         Title = script.Title.Value --- StringValue
  13.         SaveTitles:SetAsync(player.UserId, Role)
  14.     end
  15.  
  16.     local RoleValue = Instance.new("StringValue", player)
  17.     RoleValue.Name = "Title"
  18.     RoleValue.Value = Title
  19.  
  20.     player:WaitForChild("Title").Changed:Connect(function(Value)
  21.         player.Title.Value = Value
  22.     end)
  23.  
  24. end)
  25.  
  26. game:BindToClose(function()
  27.     for i,player in pairs(game.Players:GetPlayers()) do
  28.         local value = player.Title.Value
  29.         SaveTitles:SetAsync(player.UserId, value)
  30.         print("Saved data for "..player.Name)
  31.     end
  32. end)
  33.  
  34. game.Players.PlayerRemoving:Connect(function(player)
  35.     local value = player.Title.Value
  36.  
  37.     if value ~= nil then
  38.         print("Found data to save for "..player.Name.."!")
  39.         SaveTitles:SetAsync(player.UserId, value)
  40.         print("Saved data for "..player.Name)
  41.     else
  42.         print("Did not manage to find data to save for "..player.Name.."!")
  43.     end
  44. end)
  45.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement