Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. gameStats = { --[[ <-- Player can save his stats on command ]]
  2. ["DoChat?"] = {
  3. ["DoIt?"] = true;
  4. ["Keywords"] = {
  5. "/save"; "/ save";
  6. ":save"; ": save"
  7. }
  8. };
  9. ["DoMessages?"] = true; --[[ <-- Reminder of saving/loading ]]
  10. ["IsAnObby?"] = false; --[[ <-- Respawns the character to fix loading ]]
  11. saveType = {
  12. ["Normal?"] = true; --[[ <-- Set to false if other ]]
  13. ["SavingList?"] = { --[[ <-- Specific wanted admins ]]
  14. ["DoIt?"] = false;
  15. theList = {
  16. "Name1";
  17. "Name2";
  18. "Name3"
  19. }
  20. };
  21. ["BestFriends?"] = false; --[[ <-- Best friends of your's only. ]]
  22. ["Friends?"] = false; --[[ <-- Friends of your's only. ]]
  23. ["OwnerOnly?"] = false; --[[ <-- Only you have saving stats ]]
  24. ["Gamepass?"] = { --[[ <-- Needs a gamepass to save ]]
  25. ["DoIt?"] = false;
  26. ["GamepassId"] = 000000
  27. };
  28. ["Asset/Item?"] = { --[[ Such as a T-Shirt ]]
  29. ["DoIt?"] = false;
  30. ["AssetId"] = 000000
  31. }
  32. };
  33. }
  34.  
  35. --[[ The rest isn't as customizable" ]]--
  36.  
  37. debrisS, playerS, datastoreS, gamepassS, marketS =
  38. game:GetService("Debris"),
  39. game:GetService("Players"),
  40. game:GetService("DataStoreService"),
  41. game:GetService("GamePassService"),
  42. game:GetService("MarketplaceService")
  43.  
  44. function passedPlayer(p, isLeaving)
  45. print(p.Name.." has passed")
  46. local function sendMessage(txt)
  47. if gameStats["DoMessages?"] then
  48. local message = Instance.new("Message", p.PlayerGui)
  49. message.Text = txt
  50. debrisS:AddItem(message, 2)
  51. end
  52. end
  53. local save, load =
  54. function()
  55. local cDatastore, statStorage =
  56. datastoreS:GetDataStore(p.Name.."Stats"),
  57. p:WaitForChild("leaderstats"):GetChildren()
  58. for i = 1, #statStorage do
  59. cDatastore:SetAsync(statStorage[i].Name, statStorage[i].Value)
  60. end
  61.  
  62. end,
  63. function()
  64. local cDatastore, stats =
  65. datastoreS:GetDataStore(p.Name.."Stats"),
  66. p:FindFirstChild("leaderstats"):GetChildren()
  67. for i = 1, #stats do
  68. stats[i].Value = cDatastore:GetAsync(stats[i].Name)
  69. end
  70.  
  71. end
  72. local chatted = function(c)
  73. c = c:lower()
  74. for i, v in pairs(gameStats["DoChat?"]["Keywords"]) do
  75. if (c == v) then
  76. save()
  77. end
  78. end
  79. end
  80. if isLeaving then
  81. save()
  82. else
  83. load()
  84. if gameStats["DoChat?"]["DoIt?"] then
  85. p["Chatted"]:connect(chatted)
  86. end
  87. end
  88. end
  89.  
  90. function passTest(p, isLeaving)
  91. print("Test starting")
  92. if gameStats["IsAnObby?"] then
  93. local cAdded = function(c)
  94. p:LoadCharacter(true)
  95. end
  96. p["CharacterAdded"]:connect(cAdded)
  97. end
  98. if gameStats.saveType["Normal?"] then
  99. passedPlayer(p, isLeaving)
  100. else
  101. if gameStats.saveType["SavingList?"]["DoIt?"] then
  102. for i, v in pairs(gameStats.saveType["SavingList?"].theList) do
  103. if (p.Name == v) then
  104. passedPlayer(p, isLeaving)
  105. end
  106. end
  107. elseif gameStats.saveType["BestFriends?"] then
  108. if p:IsBestFriendsWith(game.CreatorId) then
  109. passedPlayer(p, isLeaving)
  110. end
  111. elseif gameStats.saveType["Friends?"] then
  112. if p:IsFriendsWith(game.CreatorId) then
  113. passedPlayer(p, isLeaving)
  114. end
  115. elseif gameStats.saveType["OwnerOnly?"] then
  116. if (p.userId == game.CreatorId) then
  117. passedPlayer(p, isLeaving)
  118. end
  119. elseif gameStats.saveType["Gamepass?"]["DoIt?"] then
  120. if p:PlayerHasPass(p, gameStats.saveType["Gamepass?"]["GamepassId"]) then
  121. passedPlayer(p, isLeaving)
  122. end
  123. elseif gameStats.saveType["Asset/Item?"]["DoIt?"] then
  124. if p:PlayerOwnsAsset(p, gameStats.saveType["Asset/Item?"]["AssetId"]) then
  125. passedPlayer(p, isLeaving)
  126. end
  127. end
  128. end
  129. end
  130.  
  131. pAdded, pLeaving =
  132. function(p)
  133. local lStats = false
  134. while true do
  135. if p:findFirstChild("leaderstats") then
  136. lStats = p:findFirstChild("leaderstats")
  137. passTest(p, false)
  138. break
  139. end
  140. wait()
  141. end
  142. end,
  143. function(p)
  144. passTest(p, true)
  145. end
  146.  
  147. playerS["PlayerAdded"]:connect(pAdded)
  148. playerS["PlayerRemoving"]:connect(pLeaving)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement