How Can I Make Kill Only Once?

So, I have this function that gives kill which runs when you kill someone with an ability. However, if you use the ability in a short time, this function will be run, and it can grant more than 1 kill from the same player. The question is how can I add like a debounce of some sort that prevent you getting more than 1 kill of the same player until they respawn again?

function Kill(Player, Humanoid)
	local KillCurrency = math.random(5, 25)
	
	if Humanoid ~= nil then
		if Humanoid.Health <= 0 then
			Player.leaderstats:FindFirstChild("Kills").Value += 1
			Player.leaderstats:FindFirstChild("Credit").Value += KillCurrency
		end
	end
end

a) A table perhaps which stores the players being hit and removed when the player dies preventing subsequent hits/kills.

b) Perhaps check if the character being hit has humanoid.Health <= 0 (you done this)

c) Check is character exists before adding any calculations (preventing dead character parts from being hit).

You also might need a way to differentiate between your character and the enemy character.

Yeah, I had an idea on making a table. However, I don’t understand on how I would remove that specific character when they respawn if you know what I mean. But thanks for tips, this function was more like a test.

You could make the player fire a remote event to the server when they respond. You would then connect the remote event fire to a function in the kill script that removes the player from the kill list. This probably isn’t the greatest solution, however

There are some ways.

local playersTable = {}

local function addPlayerToTable(player)

playersTable(player) = true --adds player
playersTable(player) = nil --removes player 

table.insert(playersTable, player) --adds player
table.remove(playersTable, table.find(playersTable, player)) --I think this removes all instances of the player

end


Something like this.

Ok, I found a new solution. You can connect a function to workspace.ChildAdded to check when something is added to the workspace. This function would iterate through the list and check if the added instance’s name is identical to the name of any of the players in the list. If it is, the added item would be removed from the list:

workspace.ChildAdded:Connect(function(child)
    for i, v in pairs(killList --Contains any players that were killed)
        if v.Name == child.Name then
            table.remove(killList, table.find(killList, v))
        end
    end
end

If it removes all instances, wouldn’t it cause the same problem? I think it should only remove one instance until they respawn. It okay if you can’t solve it; I appreciate the help.

no because you only check the characters in the table and if found then damage/award kill

I’ll give it a try later, thanks!