Damage cooldown is completely ignored

I’m making a damage part and making it so one player has a cooldown applied to them so other players can get hit by the part while its on cooldown for another player.

The thing is, it completely ignores the cooldown and instantly kills the player rapidly.

Script:

script.Parent.Touched:Connect(function(hhsh)
	
	local hits = {}
	
	if game.Players:GetPlayerFromCharacter(hhsh.Parent) then
		local char = hhsh.Parent
		if not hits[char] then
		
			hits[char] = true
		
			hhsh.Parent:FindFirstChildWhichIsA("Humanoid"):TakeDamage(5)
		
			task.wait(1)
		
			hits[char] = false
		
		end
	end	
end)

im dumb and put local hits = {} inside the touch function, new code

local hits = {}

script.Parent.Touched:Connect(function(hit)
	
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if plr ~= nil then
		
		local char = plr.Character
		local hum = char:FindFirstChildWhichIsA("Humanoid")
		
		if not hits[char] and hum ~= nil and hum.Health > 0 then
		
			hits[char] = true
		
			hum:TakeDamage(5)
		
			task.wait(1)
		
			hits[char] = false
		
		end
	end	
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.