I am trying to make a cash per kill leaderboard. I think the problem is the player variable.
local bullet = script.Parent
local headshot_sound = game.Workspace.HEADSHOT
local function player_check(otherPart)
local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
local shooter = game.Players:FindFirstChild(bullet.Attacker.Value)
local player = game.Players:FindFirstChild(humanoid.Parent.Name)
local killerTag = game.Players:FindFirstChild(player.Killer.Value)
if humanoid and otherPart.Parent.Name ~= bullet.Attacker.Value then
if player.TeamColor ~= shooter.TeamColor and game.Players:GetPlayerFromCharacter(otherPart.Parent).TeamColor ~= shooter.TeamColor then
humanoid:TakeDamage(0)
if shooter.InstaKill.Value == true then
humanoid:TakeDamage(999)
else
if otherPart.Name == 'Head' then
humanoid:TakeDamage(100)
headshot_sound:Play()
elseif otherPart.Name == "HumanoidRootPart" then
humanoid:TakeDamage(30)
else
humanoid:TakeDamage(15)
end
end
else
if player then
local tag = player:FindFirstChild('Killer')
if tag then
tag.Value = bullet.Attacker.Value
end
end
end
end
bullet:Destroy()
end
bullet.Touched:Connect(player_check)
Do you get any errors in the output?
The problem may be that killerTag is still set to nil. To check this, print(killerTag) right after you define the variable.
I believe the problem is that youâre not setting the killerTag value when a player is killed, to do this you could do something like this
if player.TeamColor ~= shooter.TeamColor and game.Players:GetPlayerFromCharacter(otherPart.Parent).TeamColor ~= shooter.TeamColor then
local damage = 0
if shooter.InstaKill.Value == true then
damage = humanoid.Health
else
if otherPart.Name == 'Head' then
damage = 100
headshot_sound:Play()
elseif otherPart.Name == "HumanoidRootPart" then
damage = 30
else
damage = 15
end
end
local finalHP = humanoid.Health - damage
if finalHP <= 0 then
local tag = player:FindFirstChild('Killer')
if tag then
tag.Value = bullet.Attacker.Value
end
end
humanoid.Health = finalHP
else
if player then
local tag = player:FindFirstChild('Killer')
if tag then
tag.Value = bullet.Attacker.Value
end
end
end