Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I check if a player killed another player? [UNSOLVED]

I have a leaderboard script which has an IntValue called points. How could I add something into the leaderboard script that detects if a player has killed someone else, and so when a player kills someone they get +10 Value for the Points IntValue

ball = script.Parent
damage = math.random(10,30)
local hitt = false

HitSound = Instance.new("Sound")
HitSound.Name = "HitSound"
HitSound.SoundId = "http://www.roblox.com/asset/?id=11945266"
HitSound.Pitch = .8
HitSound.Volume = 1
HitSound.Parent = ball

function onTouched(hit)
	if hit.Parent:findFirstChild("ForceField") ~= nil then return end
	if hit.CanCollide == false and hit.Parent:findFirstChild("Humanoid") == nil then return end
	if hit.Parent.className == "Hat" and hitt == false then
		hitt = true
		hit:BreakJoints()
		hit.Velocity = ball.Velocity
		hit.Parent.Parent = game.Workspace
	end

	if hit:findFirstChild("Metal") ~= nil and hitt == false then
		hitt = true
		for i = 1,math.random(1,3) do
			local j = Instance.new("Part")
			j.formFactor = "Plate"
			j.Size = Vector3.new(1,.4,1)
			j.BrickColor = BrickColor.new("Bright yellow")
			j.CanCollide = false
			j.Velocity = Vector3.new(math.random(-10,10),math.random(-10,10),math.random(-10,10))
			j.CFrame = script.Parent.CFrame
			j.Parent = game.Workspace
		end
	end

	local humanoid = hit.Parent:findFirstChild("Humanoid")

	if humanoid ~= nil and hitt == false then
		hitt = true
		tagHumanoid(humanoid)
		if hit.Name == "Head" then
			humanoid.Health = humanoid.Health - damage * 2
		elseif hit.Name == "Torso" then
			humanoid.Health = humanoid.Health - damage * 1.5
		else
			humanoid.Health = humanoid.Health - damage
		end
		wait(.1)
		untagHumanoid(humanoid)
	end
	if hitt == true then
		HitSound:play()
		ball.Parent = nil
	end
end

function tagHumanoid(humanoid)
	-- todo: make tag expire
	local tag = ball:findFirstChild("creator")
	if tag ~= nil then
		local new_tag = tag:clone()
		new_tag.Parent = humanoid
	end
end


function untagHumanoid(humanoid)
	if humanoid ~= nil then
		local tag = humanoid:GetChildren()

		for i = 1, #tag do

			if tag[i].Name == "creator" then
			tag[i]:remove()
			end
		
		end
	end
end

connection = ball.Touched:connect(onTouched)

while true do
wait(.01)
if damage < 0 then
break
else
damage = damage - .2
end
end

ball.Parent = nil

2 answers

✓ Accepted answer

Assuming that you're using guns then you could use raycasting to determine if, after the bullet or projectile that would do the damage did what it was intended for, the player's health was equal to 0. Then add the points.

If you're using a sort of melee weapon then use a touched event to determine if the player's health is equal to 0, and do the same thing.

Not much else I can help you with unless you provide an attempt at this.

-Goulstem

9 comments

0

ok, ill edit my question with the leaderboard

0

I mean like, an attempt at what I just told you. I know how a leaderboard would be pretty much laid out but try what I'm saying and if theres a sort of problem then come back

0

I have put the leaderboard and something to check if a player dies. But I don;t know how to make it so it checks to see which player killed that person, so in which case, causing the killer to gain 10 points,

0

Yeah I saw the like announcement for when a player dies type thing, but again, what I'm saying is to try out the things In my answer and come back if theres a problem. Or if you don't completely understand my answer.

0

I am using a free model gun, which has 500 lines of code. So I cant check

0

sorry wrong script, its about 60 lines. Unless I put this here]

0

Uhhhhhhh

0

exactly. I cant script guns so I just got a free model

0

Well you're gonna have to learn because this needs to be a custom gun,

You need to create a StringValue called "creator" in the person's humanoid with the value of the person who killed them. Have you leaderboard check when someone dies and see if that "creator" value has been created, if so, then use that value to add kills to the player who killed that player.

This discussion is preserved as it was. New answers, comments, and votes are closed.