mr2meows

Linked Leaderboard

Jul 6th, 2022 (edited)
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. --paste updated from v3 to v5
  2. print("LinkedLeaderboard script version 5.00 loaded")
  3.  
  4. stands = {}
  5. CTF_mode = false
  6.  
  7.  
  8. function onHumanoidDied(humanoid, player)
  9. local stats = player:findFirstChild("leaderstats")
  10. if stats ~= nil then
  11. local deaths = stats:findFirstChild("Wipeouts")
  12. deaths.Value = deaths.Value + 1
  13.  
  14. -- do short dance to try and find the killer
  15.  
  16. local killer = getKillerOfHumanoidIfStillInGame(humanoid)
  17.  
  18. handleKillCount(humanoid, player)
  19. end
  20. end
  21.  
  22. function onPlayerRespawn(property, player)
  23. -- need to connect to new humanoid
  24.  
  25. if property == "Character" and player.Character ~= nil then
  26. local humanoid = player.Character.Humanoid
  27. local p = player
  28. local h = humanoid
  29. humanoid.Died:connect(function() onHumanoidDied(h, p) end )
  30. end
  31. end
  32.  
  33. function getKillerOfHumanoidIfStillInGame(humanoid)
  34. -- returns the player object that killed this humanoid
  35. -- returns nil if the killer is no longer in the game
  36.  
  37. -- check for kill tag on humanoid - may be more than one - todo: deal with this
  38. local tag = humanoid:findFirstChild("creator")
  39.  
  40. -- find player with name on tag
  41. if tag ~= nil then
  42.  
  43. local killer = tag.Value
  44. if killer.Parent ~= nil then -- killer still in game
  45. return killer
  46. end
  47. end
  48.  
  49. return nil
  50. end
  51.  
  52. function handleKillCount(humanoid, player)
  53. local killer = getKillerOfHumanoidIfStillInGame(humanoid)
  54. if killer ~= nil then
  55. local stats = killer:findFirstChild("leaderstats")
  56. if stats ~= nil then
  57. local kills = stats:findFirstChild("KOs")
  58. if killer ~= player then
  59. kills.Value = kills.Value + 1
  60.  
  61. else
  62. kills.Value = kills.Value - 1
  63.  
  64. end
  65. end
  66. end
  67. end
  68.  
  69.  
  70. -----------------------------------------------
  71.  
  72.  
  73.  
  74. function findAllFlagStands(root)
  75. local c = root:children()
  76. for i=1,#c do
  77. if (c[i].className == "Model" or c[i].className == "Part") then
  78. findAllFlagStands(c[i])
  79. end
  80. if (c[i].className == "FlagStand") then
  81. table.insert(stands, c[i])
  82. end
  83. end
  84. end
  85.  
  86. function hookUpListeners()
  87. for i=1,#stands do
  88. stands[i].FlagCaptured:connect(onCaptureScored)
  89. end
  90. end
  91.  
  92. function onPlayerEntered(newPlayer)
  93.  
  94. if CTF_mode == true then
  95.  
  96. local stats = Instance.new("IntValue")
  97. stats.Name = "leaderstats"
  98.  
  99. local captures = Instance.new("IntValue")
  100. captures.Name = "Captures"
  101. captures.Value = 0
  102.  
  103.  
  104. captures.Parent = stats
  105.  
  106. -- VERY UGLY HACK
  107. -- Will this leak threads?
  108. -- Is the problem even what I think it is (player arrived before character)?
  109. while true do
  110. if newPlayer.Character ~= nil then break end
  111. wait(5)
  112. end
  113.  
  114. stats.Parent = newPlayer
  115.  
  116. else
  117.  
  118. local stats = Instance.new("IntValue")
  119. stats.Name = "leaderstats"
  120.  
  121. local kills = Instance.new("IntValue")
  122. kills.Name = "KOs"
  123. kills.Value = 0
  124.  
  125. local deaths = Instance.new("IntValue")
  126. deaths.Name = "Wipeouts"
  127. deaths.Value = 0
  128.  
  129. kills.Parent = stats
  130. deaths.Parent = stats
  131.  
  132. -- VERY UGLY HACK
  133. -- Will this leak threads?
  134. -- Is the problem even what I think it is (player arrived before character)?
  135. while true do
  136. if newPlayer.Character ~= nil then break end
  137. wait(5)
  138. end
  139.  
  140. local humanoid = newPlayer.Character.Humanoid
  141.  
  142. humanoid.Died:connect(function() onHumanoidDied(humanoid, newPlayer) end )
  143.  
  144. -- start to listen for new humanoid
  145. newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )
  146.  
  147.  
  148. stats.Parent = newPlayer
  149.  
  150. end
  151.  
  152. end
  153.  
  154.  
  155. function onCaptureScored(player)
  156.  
  157. local ls = player:findFirstChild("leaderstats")
  158. if ls == nil then return end
  159. local caps = ls:findFirstChild("Captures")
  160. if caps == nil then return end
  161. caps.Value = caps.Value + 1
  162.  
  163. end
  164.  
  165.  
  166. findAllFlagStands(game.Workspace)
  167. hookUpListeners()
  168. if (#stands > 0) then CTF_mode = true end
  169. game.Players.ChildAdded:connect(onPlayerEntered)
Add Comment
Please, Sign In to add comment