Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Keaderboard script loaded!")
- maxlevel = 50
- function onXPChanged(player, score, level)
- if score.Value>= 25 * (level.Value) + 100 and level.Value < maxlevel then
- score.Value = score.Value - (25*(level.Value) + 100)
- level.Value = level.Value + 1
- end
- end
- function onLevelUp(player, score, level)
- if player.Character~=nil then
- for i = 1,5 do
- local fireworks = Instance.new("Part")
- fireworks.Shape = 0
- fireworks.formFactor = "Symmetric"
- fireworks.Size = Vector3.new(1,1,1)
- fireworks.BrickColor = BrickColor.Random()
- fireworks.CFrame = player.Character.Head.CFrame + Vector3.new(0,2,0)
- fireworks.Parent = game.Workspace
- game:GetService("Debris"):AddItem(fireworks, 2)
- fireworks.Velocity = Vector3.new(math.random(-30,30),math.random(-30,30),math.random(-30,30))
- end
- end
- local m = Instance.new("Hint")
- m.Parent = game.Workspace
- m.Text = player.Name .. " has ranked up!" --Sweet!
- wait(5)
- m.Parent = nil
- end
- function onHumanoidDied(humanoid, player)
- local stats = player:findFirstChild("leaderstats")
- if stats ~= nil then
- local deaths = stats:findFirstChild("Dies")
- deaths.Value = deaths.Value + 1
- -- do short dance to try and find the killer
- local killer = getKillerOfHumanoidIfStillInGame(humanoid)
- handleKillCount(humanoid, player)
- end
- end
- function onPlayerRespawn(property, player)
- -- need to connect to new humanoid
- if property == "Character" and player.Character ~= nil then
- local humanoid = player.Character.Humanoid
- local p = player
- local h = humanoid
- humanoid.Died:connect(function() onHumanoidDied(h, p) end )
- end
- end
- function getKillerOfHumanoidIfStillInGame(humanoid)
- -- returns the player object that killed this humanoid
- -- returns nil if the killer is no longer in the game
- -- check for kill tag on humanoid - may be more than one - todo: deal with this
- local tag = humanoid:findFirstChild("creator")
- -- find player with name on tag
- if tag ~= nil then
- local killer = tag.Value
- if killer.Parent ~= nil then -- killer still in game
- return killer
- end
- end
- return nil
- end
- function handleKillCount(humanoid, player)
- local killer = getKillerOfHumanoidIfStillInGame(humanoid)
- if killer ~= nil then
- local stats = killer:findFirstChild("leaderstats")
- if stats ~= nil then
- local kills = stats:findFirstChild("Kills")
- local score = stats:findFirstChild("XP")
- local level = stats:findFirstChild("Rank")
- if killer ~= player then
- score.Value = score.Value + 250 *
- kills.Value = kills.Value + 1
- else
- kills.Value = kills.Value - 1
- end
- end
- end
- end
- -----------------------------------------------
- function plr(newPlayer)
- local stats = Instance.new("IntValue")
- stats.Name = "leaderstats"
- local kills = Instance.new("IntValue")
- kills.Name = "Kills"
- kills.Value = 0
- local deaths = Instance.new("IntValue")
- deaths.Name = "Dies"
- deaths.Value = 0
- local score = Instance.new("IntValue")
- score.Name = "XP"
- score.Value = 0
- local rank = Instance.new("IntValue")
- rank.Name = "Rank"
- rank.Value = 1
- local fill = Instance.new("IntValue")
- fill.Name= "filler1"
- fill.Value = 0
- rank.Parent = stats
- score.Parent = stats
- kills.Parent = stats
- deaths.Parent = stats
- fill.Parent = stats
- stats.Parent = newPlayer
- --[[ if newPlayer.usedId == 65006475 then
- newPlayer.leaderstats.Rank.Value = maxlevel
- end]]
- score.Changed:connect(function() onXPChanged(newPlayer, score, rank) end)
- rank.Changed:connect(function() onLevelUp(newPlayer, score, rank) end)
- while true do
- if newPlayer.Character ~= nil then break end
- wait(5)
- end
- local humanoid = newPlayer.Character.Humanoid
- humanoid.Died:connect(function() onHumanoidDied(humanoid, newPlayer) end )
- -- start to listen for new humanoid
- newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )
- end
- for _,v in pairs(game.Players:GetPlayers()) do
- plr(v)
- end
- game.Players.ChildAdded:connect(plr)
Add Comment
Please, Sign In to add comment