My LeaderStats are Broken? Help!
I took some parts and put them together to try to make a LeaderStats Script, so you can track your deaths and kills. Also, the kills in the future will be used to buy Paintball Guns. The script appears but on death, it didn't give the user(s) testing KO's and WO's. Please help and revise any errors, it means alot. Thank you so much!
001 | function onPlayerEntered(newPlayer) |
004 | local stats = Instance.new( "IntValue" ) |
005 | stats.Name = "leaderstats" |
007 | local kills = Instance.new( "IntValue" ) |
011 | local deaths = Instance.new( "IntValue" ) |
012 | deaths.Name = "Deaths" |
016 | deaths.Parent = stats |
020 | if newPlayer.Character ~ = nil then break end |
024 | local humanoid = newPlayer.Character.Humanoid |
026 | humanoid.Died:connect( function () onHumanoidDied(humanoid, newPlayer) end ) |
029 | newPlayer.Changed:connect( function (property) onPlayerRespawn(property, newPlayer) end ) |
032 | stats.Parent = newPlayer |
036 | function Send_DB_Event_Died(victim, killer) |
038 | local killername = "no one" |
039 | if killer ~ = nil then killername = killer.Name end |
040 | print ( "DIED EVENT: " , victim.Name, " KILLED by " , killername) |
042 | if shared [ "deaths" ] ~ = nil then |
043 | shared [ "deaths" ] (victim, killer) |
044 | print ( "SENT DB DEATH EVENT" ) |
048 | function Send_DB_Event_Kill(killer, victim) |
049 | print ( "KILL EVENT. " , killer.Name, " BLOXXED " , victim.Name) |
050 | if shared [ "kills" ] ~ = nil then |
051 | shared [ "kills" ] (killer, victim) |
052 | print ( "SENT DB KILL EVENT" ) |
058 | function onHumanoidDied(humanoid, player) |
059 | local stats = player:findFirstChild( "leaderstats" ) |
061 | local deaths = stats:findFirstChild( "Wipeouts" ) |
062 | deaths.Value = deaths.Value + 1 |
066 | local killer = getKillerOfHumanoidIfStillInGame(humanoid) |
069 | Send_DB_Event_Died(player, killer) |
070 | handleKillCount(humanoid, player) |
074 | function onPlayerRespawn(property, player) |
077 | if property = = "Character" and player.Character ~ = nil then |
078 | local humanoid = player.Character.Humanoid |
081 | humanoid.Died:connect( function () onHumanoidDied(h, p) end ) |
085 | function getKillerOfHumanoidIfStillInGame(humanoid) |
090 | local tag = humanoid:findFirstChild( "creator" ) |
095 | local killer = tag.Value |
096 | if killer.Parent ~ = nil then |
104 | function handleKillCount(humanoid, player) |
105 | local killer = getKillerOfHumanoidIfStillInGame(humanoid) |
106 | if killer ~ = nil then |
107 | local stats = killer:findFirstChild( "leaderstats" ) |
109 | local kills = stats:findFirstChild( "KOs" ) |
110 | if killer ~ = player then |
111 | kills.Value = kills.Value + 1 |
114 | kills.Value = kills.Value - 1 |
117 | Send_DB_Event_Kill(killer, player) |
122 | game.Players.ChildAdded:connect(onPlayerEntered) |