function hitDetection(hit,ray, mousepos)
local model = hit:FindFirstAncestorOfClass("Model")
if model then
local humanoid = model:FindFirstChildWhichIsA("Humanoid") or nil
if humanoid then
if hit.Name == "Head" then
humanoid:TakeDamage(configuration.HeadShotDamage)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if humanoid.Health == 0 then
player.leaderstats.Kills.Value += 1
player.RoundKills.Value += 1
end
else
humanoid:TakeDamage(configuration.Damage)
local player = game.Players:GetPlayerFromCharacter(model)
if humanoid.Health == 0 then
player:FindFirstChild("leaderstats").Kills.Value += 1
player:FindFirstChild("RoundKills").Value += 1
end
end
else
return true
end
end
end
you are attempting to call :FindFirstChild on nil. thats what it means. im gonna assume player is nil as that is the only time i see :FindFirstChild being used
he is using hit:FindFirstAncestorOfClass("Model") while also checking if theres a humanoid. so im pretty sure model is a character. plus if you do hit.Parent then what if hit is a child of an accessory?
From what I can see, you’re getting the player from the character you hit and not the character who fired the shot. This could mean that kills are given to the wrong player, and also may be causing the error since I assume you’re trying to shoot an NPC that doesn’t have a player.