I Trying Making A Combat System And I Can't Seem To Get It To Work Here Is My Code

local LPunchU = script:WaitForChild("LPunchU")
local RPunchU = script:WaitForChild("RPunchU")

local LKickU = script:WaitForChild("LKickU")
local RKickU = script:WaitForChild("RKickU")


local char = script.Parent

local humanoid = char:WaitForChild("Humanoid")


local uis = game:GetService("UserInputService")


local debounce = false
local isAnimationPlaying = false


local loadedAnimation
local currentAnimationId


local remoteEvent = game.ReplicatedStorage.OnSuccessfulHit


uis.InputBegan:Connect(function(input, gameProcessed)

	if gameProcessed or isAnimationPlaying then return end


	if input.KeyCode == Enum.KeyCode.Q then


		isAnimationPlaying = true
		currentAnimationId = LPunchU.AnimationId

		loadedAnimation = humanoid:LoadAnimation(LPunchU)

		loadedAnimation:Play()


	elseif input.KeyCode == Enum.KeyCode.E then


		isAnimationPlaying = true
		currentAnimationId = RPunchU.AnimationId

		loadedAnimation = humanoid:LoadAnimation(RPunchU)

		loadedAnimation:Play()


	elseif input.KeyCode == Enum.KeyCode.F then


		isAnimationPlaying = true
		currentAnimationId = LKickU.AnimationId

		loadedAnimation = humanoid:LoadAnimation(LKickU)

		loadedAnimation:Play()


	elseif input.KeyCode == Enum.KeyCode.G then


		isAnimationPlaying = true
		currentAnimationId = RKickU.AnimationId

		loadedAnimation = humanoid:LoadAnimation(RKickU)

		loadedAnimation:Play()
	end

	if loadedAnimation then 


		loadedAnimation.Stopped:Wait()

		isAnimationPlaying = false
	end
end)


humanoid.Touched:Connect(function(hit, bodyPart)

	if not isAnimationPlaying or debounce then return end

	local charOfHitPlayer = hit.Parent
	local humanoidOfHitPlayer = charOfHitPlayer:FindFirstChild("Humanoid")

	if not humanoidOfHitPlayer then return end

	debounce = true


	if currentAnimationId == LPunchU.AnimationId and bodyPart.Name == "LeftHand" then

		remoteEvent:FireServer(humanoidOfHitPlayer)

	elseif currentAnimationId == RPunchU.AnimationId and bodyPart.Name == "RightHand" then

		remoteEvent:FireServer(humanoidOfHitPlayer)

	elseif currentAnimationId == LKickU.AnimationId and bodyPart.Name == "LeftFoot" then

		remoteEvent:FireServer(humanoidOfHitPlayer)

	elseif currentAnimationId == RKickU.AnimationId and bodyPart.Name == "RightFoot" then

		remoteEvent:FireServer(humanoidOfHitPlayer)
	end

	wait(0.1)

	debounce = false
end)

Also I Am Getting This Error Infinite yield possible on 'Workspace.Proskillez342.Combat Handler:WaitForChild("LKickU")'

1 comment

0

NVM It Been Solve, I Was Just Being Stupid