Checking if the player is dead, giving a point, then stop giving points when that player is hit

I’m trying to check if a tool killed a player, if so give them a point. But I want to make it so that if they keep hitting then while dead, they get no more points. Problem is they have to be able to kill more than one player so there needs to be a cooldown time for only once they have killed a certain player. I tried adding the player’s names to a table and have the function ignore a player with their name in the table. Problem is it didn’t work and I can’t seem to find a fix. On another note, are there any better ways to do it?

All the code is in a script, not a localscript. I get no errors, but it just doesn’t work.

Code in a touched function (for the projectile). Already ran checks on the hit/defined all the variables:

if humanoid.Health <= 0 then
	local playerName = game.Players:GetPlayerFromCharacter(humanoid.Parent).Name
	if not ignored(playerName) then
		local pos = #ignore + 1
		table.insert(ignore, pos, tostring(playerName))
		game.ServerScriptService.Server.GivePoints:Fire(tag.Value, 1)
		coroutine.wrap(function()
		    wait(3)
			table.remove(ignore, pos)
		end)
	end
end

Code outside the touched function:

local ignore = {}
function ignored(playerName)
	for currentIgnore,_ in pairs(ignore) do
		if tostring(currentIgnore) == tostring(playerName) then
			return false
		end
	end
	return true
end
2 Likes

Hello there, in the past I had that issue and I fixed it. When the tool kills someone, it would add a value that indicates that the tool won’t get more points! What I mean is that when someone kills someone else, the tool would add a value inside the humanoid and the tool would check if that value exist(make the value anything even if it is a bool value,int value etc…) if it exists, then it won’t give points to the player. I’d also recommend that the value is checked and created server-sided to prevent exploits!!

It shouldn’t prevent the tool from getting points. It should only prevent the tool from getting points from a specific player. In this case it is 1 kill = 1 point. I don’t want the tool giving more than one point if, say the player who just killed someone starts shooting projectiles at the remains of the dead player and it keeps adding points. Say they shot a rocket at a group of players and killed 3 people. They should get all 3 points at the same time, but not be able to earn points from the players that are already dead.

What I do which is pretty bad is insert a value called “Killed” inside the Player when they join,
When a player kills another I change the value’s value to the Player that killed them,
then I have a .CharacterAdded event in that I just check if the value of the “Killed” is not “”
if so then I give the player that killed them a point and just change the Killed value back to “”
I guess you could do that even tho it is PRETTY bad but oh well
also rather than doing

		local pos = #ignore + 1
		table.insert(ignore, pos, tostring(playerName))

you could do

ignore[#ignore +1] = playerName

While this is a quick fix, it could be easily exploited. An exploiter could change their “Killed” value to true and anybody that would kill them gets no points. If this post doesn’t get some other answers, i’ll use this method but add some precautions to it to make it more secure.

You are wrong, an exploiter can modify anything on their client, but cannot modify anything when it comes to other player’s clients so it cannot be exploited.
You should also handle this on server obviously.
let me show you how I do it :slight_smile:

--This is in a server script of course.
Players.PlayerAdded:Connect(function(Player) -- Players = game:GetService('Players');
    
    local d = Instance.new'StringValue'; -- Create the StringValue which we'll change the value of it to the Killers name.
    d.Name = 'Killer';
    d.Value = "";
    d.Parent = Player; -- Parent it to the player soo it doesn't get destroyed or whatever..
    
    Player.CharacterAdded:Connect(function() -- When the player's character is added we check :
        Player.TeamColor = Teams.Dead.TeamColor; -- First we team them to the dead team (i do that idk about you)
        if d.Value ~= "" then -- I check if the value is not == "" so it actually got changed and someone killed the player ( the player wasn't killed by nothing / reset)
            local killerplayer = Players[d.Value]; -- like I said Players = game:GetService('Players'); d.Value would be the killers name.
            KillFeed:FireAllClients(d.Value,Player.Name); -- FireAllClients ( kill feed if you have one ) soo it creates a gui on their screen that someone killed another ( mine kinda looks like this https://magikmanzuwu.xyz/images/xab03giv.png )
            if killerplayer then -- check if the player still is in the game and didn't leave
                local leader = killerplayer:WaitForChild("leaderstats") -- wait for the leaderstats incase somehow it still isn't in the player
                leader:WaitForChild("Kills").Value = leader:WaitForChild("Kills").Value + 1 -- wait for kills and then add to it another kill
            end
            d.Value = "" -- change the value back to ""
        end
    end)

end);

I see no reason for this to actually get exploited

Technically, they can modify things on other players clients, but it would take a large deal of luck and trial and error, as well as your own scripts.

E.g. an exploiter launches a remote event to the server (or even a bindable event to the client, which is an easier way to abuse client-wise), then when the remote event collects data from said client, it launches a function to update all the other clients with the data, in this case, the exploiter would have been able to modify not only their client, but the other clients.

Though, this is easier to fix by just getting into good practices and being more careful when writing your code.

Using Humanoid.Died is probably better, in your code snippet, as you would have to wait a period of time after the death (assuming they haven’t fiddled with spawns), before assigning “points”.

I am just going to pretend I never read what you just wrote and just saw the

You’re correct I guess I kinda forgot it existed. thanks

Sorry what?

No they can’t, whatsoever, unless your code structure is bad enough to allow that to happen. The scenario you explained is exploiters taking advantage of bad code structure. Exploiters cannot modify anything on other clients, with the exception of various things such as parts they network own.

2 Likes

Yeah - thats what I said

The scenario I gave only works depending on your own scripts - sorry if that wasn’t clear.

That doesn’t make much sense then. Clients aren’t modifying other clients. They’re tampering with an insecure structure which the server takes as bona fide and sends back, legitimately, data to other clients.

The scenarios you provided are relatively different. A client tampering another client is not the same as leveraging a remote with poor or no security.

2 Likes