I am trying to make a kills leaderboard and am editing the script for a rocket launcher so that it gives the player a point for every kill. The script is specifically the one which is copied into any rocket that is fired.
Below is the portion of the script defining the function that kills players (other than the one who fired the rocket, to allow for rocket jumping). The CreatorTag value is the name of the player who fired the rocket, so I used it to find the player and give them points.
local function OnExplosionHit(hitPart)
if hitPart then
local _, humanoid = FindCharacterAncestor(hitPart.Parent)
if humanoid and humanoid.Health > 0 and not hitPart:IsDescendantOf(CreatorTag.Value.Character) then
CreatorTag:Clone().Parent=humanoid
humanoid:TakeDamage(100)
-- everything below this line is what I added to the script
local character = CreatorTag.Value
local player = game.Players:FindFirstChild(character)
print(player.Name .. " got a kill")
player.leaderstats.Kills.Value = player.leaderstats.Kills.Value + 1
end
end
end
…and here it is in action:
As you can see it doesn’t work, but if I change the parameter of FindFirstChild to my actual player name and not the variable which should contain it, it works just fine.
I seriously don’t know what I’ve done wrong. Is this a bug? I’m sure the CreatorTag value is the exact same as my name. Does anybody know what’s going on and what I can do?