Advertisement
Psykiatric

Roblox Exp and Cash on kill

Feb 27th, 2018
4,957
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. print("Leaderboard script version 3.00 loaded")
  2.  
  3. function onPlayerEntered(newPlayer)
  4.  
  5.  
  6. local stats = Instance.new("IntValue")
  7. stats.Name = "leaderstats"
  8.  
  9. local kills = Instance.new("IntValue")
  10. kills.Name = "Exp."
  11. kills.Value = 0
  12.  
  13. local kills2 = Instance.new("IntValue")
  14. kills2.Name = "Cash"
  15. kills2.Value = 0
  16.  
  17. kills.Parent = stats
  18. kills2.Parent = stats
  19.  
  20. while true do
  21. if newPlayer.Character ~= nil then break end
  22. wait(5)
  23. end
  24.  
  25. local humanoid = newPlayer.Character.Humanoid
  26.  
  27. humanoid.Died:connect(function() onHumanoidDied(humanoid, newPlayer) end )
  28.  
  29. newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )
  30.  
  31.  
  32. stats.Parent = newPlayer
  33.  
  34. end
  35.  
  36. function Send_DB_Event_Died(victim, killer)
  37. local killername = "no one"
  38. if killer ~= nil then killername = killer.Name end
  39. print("DIED EVENT: ", victim.Name, " KILLED by ", killername)
  40.  
  41. if shared["deaths"] ~= nil then
  42. shared["deaths"](victim, killer)
  43. print("SENT DB DEATH EVENT")
  44. end
  45. end
  46.  
  47. function Send_DB_Event_Kill(killer, victim)
  48. print("KILL EVENT. ", killer.Name, " BLOXXED ", victim.Name)
  49. if shared["kills"] ~= nil then
  50. shared["kills"](killer, victim)
  51. print("SENT DB KILL EVENT")
  52. end
  53. end
  54.  
  55.  
  56.  
  57. function onHumanoidDied(humanoid, player)
  58. local stats = player:findFirstChild("leaderstats")
  59. if stats ~= nil then
  60. local deaths = stats:findFirstChild("Cash")
  61. deaths.Value = deaths.Value + 0
  62.  
  63. local killer = getKillerOfHumanoidIfStillInGame(humanoid)
  64.  
  65.  
  66. Send_DB_Event_Died(player, killer)
  67. handleKillCount(humanoid, player)
  68. end
  69. end
  70.  
  71. function onPlayerRespawn(property, player)
  72.  
  73. if property == "Character" and player.Character ~= nil then
  74. local humanoid = player.Character.Humanoid
  75. local p = player
  76. local h = humanoid
  77. humanoid.Died:connect(function() onHumanoidDied(h, p) end )
  78. end
  79. end
  80.  
  81. function getKillerOfHumanoidIfStillInGame(humanoid)
  82.  
  83. local tag = humanoid:findFirstChild("creator")
  84.  
  85.  
  86. if tag ~= nil then
  87.  
  88. local killer = tag.Value
  89. if killer.Parent ~= nil then
  90. return killer
  91. end
  92. end
  93.  
  94. return nil
  95. end
  96.  
  97. function handleKillCount(humanoid, player)
  98. local killer = getKillerOfHumanoidIfStillInGame(humanoid)
  99. if killer ~= nil then
  100. local stats = killer:findFirstChild("leaderstats")
  101. if stats ~= nil then
  102. local kills = stats:findFirstChild("Exp.")
  103. local kills2 = stats:findFirstChild("Cash")
  104. if killer ~= player then
  105. kills.Value = kills.Value + 5
  106. kills2.Value = kills2.Value + 10
  107. else
  108. kills.Value = kills.Value - 0
  109. kills2.Value = kills2.Value - 0
  110. end
  111. Send_DB_Event_Kill(killer, player)
  112. end
  113. end
  114. end
  115.  
  116. game.Players.ChildAdded:connect(onPlayerEntered)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement