Advertisement
SoloVisionGaming

Kills and deaths

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