Hi! I’ve been trying to create a damage module for my fighting game, but the damage cooldown part doesn’t seem to work. It’s supposed to search for the player in the debounce table, and if it doesn’t find it, it’s supposed to damage the player and some other stuff. Even though the player does get inserted into the table, the first if statement still runs.
The issue is that the first if statement runs even though the player is in the table. I’ll add a video to demonstrate.
I have had a difficult time finding any information on the topic, so I decided to post it here.
Here’s the code:
local dmg = {
takedmg = function(hit, damage, level, cooldown, color)
local debounce = {}
if not table.find(debounce, hit.Parent) then
if color == nil then
color = Color3.new(0.7,0,0)
end
hit.Parent.Humanoid.Health -= damage + (damage / 10) * level
print("was2")
table.insert(debounce, hit.Parent)
print("is1")
local counter = Instance.new("BillboardGui")
counter.Parent = hit.Parent.HumanoidRootPart
local much = Instance.new("TextLabel")
much.Parent = counter
much.TextColor3 = color
much.Text = (damage + damage / 10) * level
end
if table.find(debounce,hit.Parent) then
print("is")
task.wait(cooldown)
table.remove(debounce, table.find(debounce, hit.Parent))
end
end
}
return dmg
Here’s the video: