I’m trying to make a kill counter that detects when you kill someone with your gun (obviously) and it works great except for the fact that if you shoot any of the pieces of the dead player, you’ll get extra kills credited to you. Any way to fix this?
local model = hitPart:FindFirstAncestorOfClass("Model")
local name = model
if model then
if model:FindFirstChild("Humanoid") then
model.Humanoid.Health -= 30
if model.Humanoid.Health <= 0 then
kills.Value = kills.Value + 1
local model = hitPart.Parent
if not model:findFirstChild("Humanoid") then return end
model.Humanoid:TakeDamage(30)
if model.Humanoid.Health <= 0 then
kills.Value = kills.Value + 1
But this one will bug doe to,
You can shoot the humanoid now 30 times whilst its dead and that will basically ruin the kills.
Best way would be to add a “Tag” inside the Humanoid, and put inside the plrscharacter a script to check if Humanoid died and if Humanoid finds a Tag,
Tag = A ObjectValue
Tag.Value.Kills.Value=Tag.Value.Kills.Value+1
In total:
local humanoid = script.Parent.Humanoid
humanoid.Died:connect(function()
if humanoid:findFirstChild("Tag") then
local tag = humanoid.Tag
local plr = tag.Value -- the plr he got killed by
-- ur thing here
end
end)
Your damage script
local a = game.Players.LocalPlayer--for test
local model = hitPart.Parent
local humanoid = model:findFirstChild("Humanoid")
if not humanoid then return end
humanoid:TakeDamage(30)
if humanoid:findFirstChild("Tag") then
humanoid.Tag.Value = a--plr he got hit by
else
local tag = Instance.new("ObjectValue",humanoid) tag.Name = "Tag" tag.Value = a--plr he got hit by
end
If you wanted to keep it simple you could have 2 if statements for testing the current health of the player to deal damage, and then award a kill.
if humanoid.Health > 0 then
--//It's alive, deal damage
humanoid:TakeDamage(30)
if humanoid.Health <= 0 then
--//Humanoid has died, award kill
kills.Value += 1
end
end
Again, a ridiculously late response but now the output says there is a parenthesis that wasn’t closed but I can’t tell where. It probably in this script since my script didn’t have any unclosed parenthesis problems. But anyways, I can’t tell where your script’s unclosed parenthesis is
local a = game.Players.LocalPlayer–for test
-- Can't find the unclosed parenthesis
local model = hitPart.Parent
local humanoid = model:findFirstChild("Humanoid")
if not humanoid then return end
humanoid:TakeDamage(30)
if humanoid:findFirstChild("Tag") then
humanoid.Tag.Value = a--plr he got hit by
else
local tag = Instance.new("ObjectValue",humanoid) tag.Name = "Tag" tag.Value = a--plr he got hit by
end