Is there a way to decrease the lag in my skill?

I created a method in which everyone who touches the “Rock” of the ability will take damage at least once, only whenever he checks if the Character is in the table of the Characters who took damage from the lag because it is called many times

local HumanoidsDamaged = {}

Rock.Touched:Connect(function(hit)		
 local CharHited = hit.Parent
			if not table.find(HumanoidsDamaged,CharHited) then
				if CharHited:FindFirstChild("Zombie") and CharHited ~= char then
					hit.Parent:FindFirstChild("Zombie"):TakeDamage(damage);
					table.insert(HumanoidsDamaged,CharHited)
				end
		end
end)
1 Like

I hope this help you.

local TouchedHumanoids = {}
local connection

connection = script.Parent.Touched:Connect(function(hit)
	local char = hit.Parent
	if char and not TouchedHumanoids[char] then
		TouchedHumanoids[char] = true
		char:findFirstChild("Humanoid"):TakeDamage(5)
		connection:Disconnect()
	end
end)
1 Like