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

How to detect if a player killed another player?

Asked by 9 years ago

How would a script detect if a player killed another player?

Thank you!

0
Take a look at the LinkedLeaderboard in the Game Stuff section of the Toolbox. Tkdriverx 514 — 9y

2 answers

Log in to vote
9
Answered by
Kratos232 105
9 years ago

First you need a script or leaderboard script, that's something like

Players = Game:GetService("Players")
Players.PlayerAdded:connect(function(Player)
    --// Empty
end)

With this, you'll have everyone who joins... But then you need to know when anyone respawns, so just add CharacterAdded.

Players = Game:GetService("Players")
Players.PlayerAdded:connect(function(Player)

    --// You can add other stuff if you want here, e.g leaderboard.

    Player.CharacterAdded:connect(function(Character)

    end)
end)

Now you have everyone's Character. All that's left is to detect when they die. To do this, just find the Character's Humanoid (Character:WaitForChild("Humanoid")), then wait for it's "Died" event. Then, if you're using swords, like the LinkedSword, they usually create an ObjectValue inside a Player's Humanoid whenever they Damage them, and remove any others, and name it "creator". So, if your weapons/killing devices don't already "tag" (add the ObjectValue to") the Humanoid, then add a function so it does. (Look in LinkedSword or something.)

So, overall, it's something like this;

Players = Game:GetService("Players") -- In case someone renames Players or something
Players.PlayerAdded:connect(function(Player) -- When someone joins
    --// You can add other stuff here, too.
    Player.CharacterAdded:connect(function(Character) -- When they respawn (Get a new Character)
        local Humanoid = Character:WaitForChild("Humanoid") -- Find Humanoid
        Humanoid.Died:connect(function() -- Detects for when the Humanoid dies
            if Humanoid:FindFirstChild("creator") ~= nil then -- Checks for a Killed
                local Killer = Humanoid.creator.Value -- Gets Killer
                -- Whatever you want to happen to the Killer
                -- You could like Jail(Killer) if you want. He did kill someone.
            end -- Ends the if
            -- For the Dead guy, you can do stuff to him here.
        end)
    end)
end) -- Another End w/ a Bracket

Well, I hope there wasn't anything wrong in this answer... And that it helped. :) Actually, I think there might be something wrong... Now I'm all scared and stuff... :c

  • Kratos232
0
Much better explanation than most. Just saying, go look at a script won't help anyone because we need an explanation Yeevivor4 155 — 9y
0
Players = Game:GetService("Players") -- Game is deprecated. You should use game:GetService("Players") Toxicheroking77 -8 — 3y
Ad
Log in to vote
-5
Answered by 9 years ago

Hmm. This is a hard one. Well, you got lucky. There is a KilledFrame in ROBLOX Battle, the one by Games. It in the StarterGUI.

Answer this question