Help detecting what player hit a player

if sword has hitbox part then you can use this script:

local hitbox=script.Parent --hitbox part here
local damage=5
local debounce=false --this is cooldown
local cooldown=2 --seconds
hitbox.Touched:Connect(function(HitPart) --when hitbox touches something
	if game:GetService("Players"):GetPlayerFromCharacter(HitPart.Parent) then --if parent of hitpart is a player
		local humanoid=HitPart.Parent:FindFirstChild("Humanoid") --humanoid of player you hit
		if humanoid and not debounce then
			debounce=true
			humanoid:TakeDamage(damage)	
		end
	end
end)
while true do --cooldown
	repeat task.wait() until debounce
	task.wait(cooldown)
	debounce=false
end
2 Likes