Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

LeaderStats? Recording Kills.

Asked by 8 years ago

Okay so I'm trying to create a script that checks when a player has killed another player or Npc here's what i got.

if part then -- 'part' is the raycasting bullet
                local humanoid = part.Parent:FindFirstChild("Humanoid")
                local head = part
                if not head then

                end
                if head and head.Name == "Head" then
                    local debounce = false
                    head.Parent:FindFirstChild("Humanoid"):TakeDamage(25)
                    if humanoid.Health == 0 and not debounce then
                        debounce = true
                        player.leaderstats.Kills.Value = player.leaderstats.Kills.Value + 1
                        wait(3)
                        debounce = false
                    end
                end
                if not humanoid then
                    humanoid = part.Parent.Parent:FindFirstChild("Humanoid")

                end

                if humanoid then
                    humanoid:TakeDamage(6)

                end
                if humanoid.Health == 0 then  -- This is where i get all my errors from
                    local playerw = game.Players:GetPlayerFromCharacter(part)
                    playerw.leaderstats.Kills.Value = player.leaderstats.Kills.Value + 1
                end
            end

1 answer

Log in to vote
1
Answered by
yoshi8080 445 Moderation Voter
8 years ago

I would use the humanoid Died function for this. I think you would replace if humanoid.Health == 0 then with humanoid.Died:connect(function() Not sure if it'll work, I haven't tested it yet.

0
Thank You So much! GeezuzFusion 200 — 8y
Ad

Answer this question