lotushomerun

Leaderboard Script(Roblox)

Apr 30th, 2017
6,233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.03 KB | None | 0 0
  1. print("Keaderboard script loaded!")
  2.  
  3. maxlevel = 50
  4.  
  5. function onXPChanged(player, score, level)
  6.         if score.Value>= 25 * (level.Value) + 100 and level.Value < maxlevel then
  7.             score.Value = score.Value - (25*(level.Value) + 100)
  8.             level.Value = level.Value + 1
  9.         end
  10.     end
  11.  
  12. function onLevelUp(player, score, level)
  13. if player.Character~=nil then
  14. for i = 1,5 do
  15. local fireworks = Instance.new("Part")
  16. fireworks.Shape = 0
  17. fireworks.formFactor = "Symmetric"
  18. fireworks.Size = Vector3.new(1,1,1)
  19. fireworks.BrickColor = BrickColor.Random()
  20. fireworks.CFrame = player.Character.Head.CFrame + Vector3.new(0,2,0)
  21. fireworks.Parent = game.Workspace
  22. game:GetService("Debris"):AddItem(fireworks, 2)
  23. fireworks.Velocity = Vector3.new(math.random(-30,30),math.random(-30,30),math.random(-30,30))
  24. end
  25. end
  26. local m = Instance.new("Hint")
  27. m.Parent = game.Workspace
  28. m.Text = player.Name .. " has ranked up!" --Sweet!
  29. wait(5)
  30. m.Parent = nil
  31. end
  32.  
  33.  
  34.  
  35. function onHumanoidDied(humanoid, player)
  36.     local stats = player:findFirstChild("leaderstats")
  37.     if stats ~= nil then
  38.         local deaths = stats:findFirstChild("Dies")
  39.         deaths.Value = deaths.Value + 1
  40.        
  41.  
  42.         -- do short dance to try and find the killer
  43.  
  44.         local killer = getKillerOfHumanoidIfStillInGame(humanoid)
  45.  
  46.         handleKillCount(humanoid, player)
  47.     end
  48. end
  49.  
  50. function onPlayerRespawn(property, player)
  51.     -- need to connect to new humanoid
  52.    
  53.     if property == "Character" and player.Character ~= nil then
  54.         local humanoid = player.Character.Humanoid
  55.             local p = player
  56.             local h = humanoid
  57.             humanoid.Died:connect(function() onHumanoidDied(h, p) end )
  58.     end
  59. end
  60.  
  61. function getKillerOfHumanoidIfStillInGame(humanoid)
  62.     -- returns the player object that killed this humanoid
  63.     -- returns nil if the killer is no longer in the game
  64.  
  65.     -- check for kill tag on humanoid - may be more than one - todo: deal with this
  66.     local tag = humanoid:findFirstChild("creator")
  67.  
  68.     -- find player with name on tag
  69.     if tag ~= nil then
  70.        
  71.         local killer = tag.Value
  72.         if killer.Parent ~= nil then -- killer still in game
  73.             return killer
  74.         end
  75.     end
  76.  
  77.     return nil
  78. end
  79.  
  80. function handleKillCount(humanoid, player)
  81.     local killer = getKillerOfHumanoidIfStillInGame(humanoid)
  82.     if killer ~= nil then
  83.         local stats = killer:findFirstChild("leaderstats")
  84.         if stats ~= nil then
  85.             local kills = stats:findFirstChild("Kills")
  86.             local score = stats:findFirstChild("XP")
  87.             local level = stats:findFirstChild("Rank")
  88.             if killer ~= player then
  89.                 score.Value = score.Value + 250 *
  90.                 kills.Value = kills.Value + 1
  91.                
  92.             else
  93.                 kills.Value = kills.Value - 1
  94.             end
  95.         end
  96.     end
  97. end
  98.  
  99.  
  100. -----------------------------------------------
  101. function plr(newPlayer)
  102.         local stats = Instance.new("IntValue")
  103.         stats.Name = "leaderstats"
  104.  
  105.         local kills = Instance.new("IntValue")
  106.         kills.Name = "Kills"
  107.         kills.Value = 0
  108.  
  109.         local deaths = Instance.new("IntValue")
  110.         deaths.Name = "Dies"
  111.         deaths.Value = 0
  112.  
  113.         local score = Instance.new("IntValue")
  114.         score.Name = "XP"
  115.         score.Value = 0
  116.  
  117.         local rank = Instance.new("IntValue")
  118.         rank.Name = "Rank"
  119.         rank.Value = 1
  120.  
  121.         local fill = Instance.new("IntValue")
  122.         fill.Name= "filler1"
  123.         fill.Value = 0
  124.        
  125.         rank.Parent = stats
  126.         score.Parent = stats
  127.         kills.Parent = stats
  128.         deaths.Parent = stats
  129.         fill.Parent = stats
  130.         stats.Parent = newPlayer
  131.  
  132.     --[[    if newPlayer.usedId == 65006475 then
  133.         newPlayer.leaderstats.Rank.Value = maxlevel
  134.         end]]
  135.  
  136.     score.Changed:connect(function() onXPChanged(newPlayer, score, rank) end)
  137.     rank.Changed:connect(function() onLevelUp(newPlayer, score, rank) end)
  138.  
  139.         while true do
  140.             if newPlayer.Character ~= nil then break end
  141.             wait(5)
  142.         end
  143.  
  144.         local humanoid = newPlayer.Character.Humanoid
  145.  
  146.         humanoid.Died:connect(function() onHumanoidDied(humanoid, newPlayer) end )
  147.  
  148.         -- start to listen for new humanoid
  149.         newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )
  150.         end
  151.  
  152.  
  153.         for _,v in pairs(game.Players:GetPlayers()) do
  154.     plr(v)
  155. end
  156.  
  157. game.Players.ChildAdded:connect(plr)
Add Comment
Please, Sign In to add comment