I’m trying to make it so when a player gets damaged, even if he gets hit with an ability that does damage, until the cooldown is over he can’t take damage. How can I do this?
You can make a value and put it in the tool, name the value as IsDamage.
If the value is true then do damage
if its false then dont do damage
(you can use if statments for that ^)
after that you can insert to your script to make the value false after the player pressed the key.
wait(3) -- or your cool down
and after the wait make the value to true.
Done.
You’re right… but this only makes it so the tool doesn’t do damage, I’m trying to make it so only the player that has taken damage has a cooldown and not the tool itself
You can use debounce! You can make it so that if the debounce is set to false only then will the ability do damage. It’s basically a variable which you set to true when the ability does damage, after 2 seconds (or whatever you want the cooldown time to be) you set it to false again!
As YelllowBanana said you can use debounce. Its an really good option.
Or as I said you can put the if statement as I said up at the start of the code.
You could try this, but note that this is a example, and the thing is that using debounce or a value to keep track of the hitting status and making a cooldown system is a good practice and very useful since most RPGs and modern simulators use some kind of cooldown system value based.
-- Constants
db = false
cooldown_time = 0.5
-- Variables
local Tool = script.Parent
-- Functions
local function main()
if db == false then
db = true
--do hitting
wait(tonumber(cooldown_time))
db = false
else
wait(tonumber(cooldown_time))
db = false
end
end)
-- Events
Tool.MouseClicked:Connect(main())
I don’t think you understood me.
Anyways, I got something to work.
module.takeDamage = function(humanoid, cooldown, damage)
local check = list[table.find(list, humanoid.Parent.Name)]
if not check then
table.insert(list, humanoid.Parent.Name)
humanoid:TakeDamage(damage)
end
coroutine.resume(coroutine.create(function()
wait(cooldown)
table.remove(list, table.find(list, humanoid.Parent.Name))
end))
end
basically this creates a table of players and it appends the player’s name that took damage to this list and after a bit the players name gets removed. this makes it so the tool itself doesn’t have a cooldown, but the players that take damage do