How would a script detect if a player killed another player?
Thank you!
How would a script detect if a player killed another player?
Thank you!
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
Much better explanation than most. Just saying, go look at a script won't help anyone because we need an explanation
Players = Game:GetService("Players") -- Game is deprecated. You should use game:GetService("Players")
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Take a look at the LinkedLeaderboard in the Game Stuff section of the Toolbox.