Ok so say a play clicked to punch and no one was hit, if the player were then to walk up to an NPC or another player (no matter how long the wait), it would then inflict the damage. How do I make it so that if no one is hit, no damage will be dealt when they walk into the player later on?

Problem: https://gyazo.com/74cb2775e2ddb3dbfe9fecad40c52898

script.Parent.RemoteEvent.OnServerEvent:Connect(function(Player)
	
debounce = false
print("yes")
local Character = Player.Character
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://2143297430"
local Animation = Character:FindFirstChild("Humanoid"):LoadAnimation(Anim)
Animation:Play()

local function onHit(hit)
	
	if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") ~= nil
	and hit.Parent.Name ~= Player.Name and debounce == false then
		
		debounce = true
		local Humanoid = hit.Parent.Humanoid
		Humanoid:TakeDamage(15)
		
	else if not hit then
		end
	end
end

	Character.RightLowerArm.Touched:Connect(onHit)
	wait(0.5)
	
end)

2 comments

0

The script is executing when your RightLowerArm touches another player, not when you click. Make it damage if your RightLowerArm is touching a player AND the punch button is clicked

0

^ Xdeno is right