Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local TeleportService = game:GetService("TeleportService")
- local SaveTitles = game:GetService("DataStoreService"):GetDataStore("Title")
- game.Players.PlayerAdded:Connect(function(player)
- local PreviousData = SaveTitles:GetAsync(player.UserId)
- local Title
- if PreviousData ~= nil then
- Title = PreviousData
- else
- Title = script.Title.Value --- StringValue
- SaveTitles:SetAsync(player.UserId, Role)
- end
- local RoleValue = Instance.new("StringValue", player)
- RoleValue.Name = "Title"
- RoleValue.Value = Title
- player:WaitForChild("Title").Changed:Connect(function(Value)
- player.Title.Value = Value
- end)
- end)
- game:BindToClose(function()
- for i,player in pairs(game.Players:GetPlayers()) do
- local value = player.Title.Value
- SaveTitles:SetAsync(player.UserId, value)
- print("Saved data for "..player.Name)
- end
- end)
- game.Players.PlayerRemoving:Connect(function(player)
- local value = player.Title.Value
- if value ~= nil then
- print("Found data to save for "..player.Name.."!")
- SaveTitles:SetAsync(player.UserId, value)
- print("Saved data for "..player.Name)
- else
- print("Did not manage to find data to save for "..player.Name.."!")
- end
- end)
Advertisement
Comments
-
- https://t.me/xmarys_x_bot?start=ref-67bbfd1887403
Add Comment
Please, Sign In to add comment
Advertisement