Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.81 KB | None | 0 0
  1. --rbxsig%XYC6H9oKVLF//1itmbaGn5wI5a4YNtkf4beIsIVZsrT29WveOsrP4YfpYDED5Xa8A1oBA/5oDwtjy4/wlvl/DH0rigLCzfNVjszNya26GajrkOvCFifnNhOCVAOLBySGJ7z5gMoZR/XQjW5EO+K1zDWiQi5CLNwBOxOTMDLS8dU=%
  2. --rbxassetid%1018966%
  3.  
  4. --edited by Exeriousless
  5. print("LinkedLeaderboard script version 5.00 loaded")
  6.  
  7. stands = {}
  8. CTF_mode = false
  9. local Data=game:GetService("DataStoreService"):GetDataStore("LeaderStatData")
  10.  
  11.  
  12. function onHumanoidDied(humanoid, player)
  13. local stats = player:findFirstChild("leaderstats")
  14. if stats ~= nil then
  15. local deaths = stats:findFirstChild("Deaths")
  16. deaths.Value = deaths.Value + 1
  17.  
  18. -- do short dance to try and find the killer
  19.  
  20. local killer = getKillerOfHumanoidIfStillInGame(humanoid)
  21.  
  22. handleKillCount(humanoid, player)
  23. end
  24. end
  25.  
  26. function onPlayerRespawn(property, player)
  27. -- need to connect to new humanoid
  28.  
  29. if property == "Character" and player.Character ~= nil then
  30. local humanoid = player.Character.Humanoid
  31. local p = player
  32. local h = humanoid
  33. humanoid.Died:connect(function() onHumanoidDied(h, p) end )
  34. end
  35. end
  36.  
  37. function getKillerOfHumanoidIfStillInGame(humanoid)
  38. -- returns the player object that killed this humanoid
  39. -- returns nil if the killer is no longer in the game
  40.  
  41. -- check for kill tag on humanoid - may be more than one - todo: deal with this
  42. local tag = humanoid:findFirstChild("creator")
  43.  
  44. -- find player with name on tag
  45. if tag ~= nil then
  46.  
  47. local killer = tag.Value
  48. if killer.Parent ~= nil then -- killer still in game
  49. return killer
  50. end
  51. end
  52.  
  53. return nil
  54. end
  55. game.Players.PlayerRemoving:connect(function(plr)
  56. local key="key"..plr.userId
  57. if plr.leaderstats:FindFirstChild("Credits") then
  58. local SaveTable={}
  59. SaveTable.Credits=plr.leaderstats.Credits.Value
  60. Data:SetAsync(key,SaveTable)
  61. end
  62. end)
  63.  
  64. function handleKillCount(humanoid, player)
  65. local killer = getKillerOfHumanoidIfStillInGame(humanoid)
  66. if killer ~= nil then
  67. local stats = killer:findFirstChild("leaderstats")
  68. if stats ~= nil then
  69. local kills = stats:findFirstChild("Kills")
  70. if killer ~= player then
  71. kills.Value = kills.Value + 1
  72. end
  73. local credits = stats:findFirstChild("Credits")
  74. if killer ~= player then
  75. credits.Value = credits.Value + 0
  76. game:service'PointsService':AwardPoints(killer.userId,5)
  77. end
  78. end
  79. end
  80. end
  81.  
  82.  
  83. -----------------------------------------------
  84.  
  85.  
  86.  
  87. function findAllFlagStands(root)
  88. local c = root:children()
  89. for i=1,#c do
  90. if (c[i].className == "Model" or c[i].className == "Part") then
  91. findAllFlagStands(c[i])
  92. end
  93. if (c[i].className == "FlagStand") then
  94. table.insert(stands, c[i])
  95. end
  96. end
  97. end
  98.  
  99. function hookUpListeners()
  100. for i=1,#stands do
  101. stands[i].FlagCaptured:connect(onCaptureScored)
  102. end
  103. end
  104.  
  105. function onPlayerEntered(newPlayer)
  106.  
  107. if CTF_mode == true then
  108.  
  109. local stats = Instance.new("IntValue")
  110. stats.Name = "leaderstats"
  111.  
  112. local captures = Instance.new("IntValue")
  113. captures.Name = "Captures"
  114. captures.Value = 0
  115.  
  116.  
  117. captures.Parent = stats
  118.  
  119. -- VERY UGLY HACK
  120. -- Will this leak threads?
  121. -- Is the problem even what I think it is (player arrived before character)?
  122. while true do
  123. if newPlayer.Character ~= nil then break end
  124. wait(5)
  125. end
  126.  
  127. stats.Parent = newPlayer
  128.  
  129. else
  130.  
  131.  
  132. local stats = Instance.new("IntValue")
  133. stats.Name = "leaderstats"
  134.  
  135. local kills = Instance.new("IntValue")
  136. kills.Name = "Kills"
  137. kills.Value = 0
  138.  
  139. local deaths = Instance.new("IntValue")
  140. deaths.Name = "Deaths"
  141. deaths.Value = 0
  142.  
  143. local credits = Instance.new('IntValue',stats)
  144. credits.Name='Credits'
  145.  
  146. local rank = Instance.new('StringValue',stats)
  147. rank.Value=newPlayer:GetRoleInGroup(514785)
  148. rank.Name='Rank'
  149.  
  150. kills.Parent = stats
  151. deaths.Parent = stats
  152.  
  153.  
  154. local key="key"..newPlayer.userId
  155. local get=Data:GetAsync(key)
  156. if get~=nil then
  157. credits.Value=get.Credits
  158. end
  159.  
  160. -- VERY UGLY HACK
  161. -- Will this leak threads?
  162. -- Is the problem even what I think it is (player arrived before character)?
  163. while true do
  164. if newPlayer.Character ~= nil then break end
  165. wait(5)
  166. end
  167. spawn(function()
  168. while wait(60) do
  169. if rank.Value~='Guest' then
  170. credits.Value=credits.Value+15
  171. else
  172. credits.Value=credits.Value+15
  173. end
  174. end
  175. end)
  176. repeat wait() until newPlayer.Character:FindFirstChild("Humanoid")
  177. local humanoid = newPlayer.Character.Humanoid
  178.  
  179. humanoid.Died:connect(function() onHumanoidDied(humanoid, newPlayer) end )
  180.  
  181. -- start to listen for new humanoid
  182. newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )
  183.  
  184.  
  185. stats.Parent = newPlayer
  186.  
  187. end
  188.  
  189. end
  190.  
  191.  
  192. function onCaptureScored(player)
  193.  
  194. local ls = player:findFirstChild("leaderstats")
  195. if ls == nil then return end
  196. local caps = ls:findFirstChild("Captures")
  197. if caps == nil then return end
  198. caps.Value = caps.Value + 1
  199.  
  200. end
  201.  
  202.  
  203. findAllFlagStands(game.Workspace)
  204. hookUpListeners()
  205. if (#stands > 0) then CTF_mode = true end
  206.  
  207. game.Players.ChildAdded:connect(onPlayerEntered)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement