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
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
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
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.