Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I need help fixing this combat script. The knockback applies too fast. Can anyone help me?

The knockback is applied too fast and I don't know how t fix it. Whenever the 4th punch hits, it applies knockback, instead of the 5th.

debounce = false combo = 1

script.Parent.OnServerEvent:Connect(function(player, action) local character = player.Character if debounce then return end

if action == "combat" then
	debounce = true
	if combo == 1 then
		combo = 2
		local rightPunch = character.Humanoid:LoadAnimation(script.rightPunch)
		rightPunch:Play()
	elseif combo == 2 then
		combo = 3
		local leftPunch = character.Humanoid:LoadAnimation(script.leftPunch)
		leftPunch:Play()
	elseif combo == 3 then
		combo = 4
		local rightUppercut = character.Humanoid:LoadAnimation(script.rightUppercut)
		rightUppercut:Play()
	elseif combo == 4 then
		combo = 5
		local leftUppercut = character.Humanoid:LoadAnimation(script.leftUppercut)
		leftUppercut:Play()
	elseif combo == 5 then
		combo = 1
		local spinKick = character.Humanoid:LoadAnimation(script.spinKick)
		spinKick:Play()
	end
	wait(0.2)
	local ray = Ray.new(character.HumanoidRootPart.Position, character.HumanoidRootPart.CFrame.lookVector * 8)
	local calcRay = workspace:FindPartOnRay(ray, character)
	if calcRay then
		if calcRay.Parent:FindFirstChild("Humanoid") and calcRay.Parent ~= character then
			calcRay.Parent.Humanoid:TakeDamage(5)
			local hitSound = script.hitSound:Clone()
			hitSound.Parent = calcRay
			hitSound:Play()
			if combo == 5 then
				local bodyVelocity = Instance.new("BodyVelocity", calcRay)
				bodyVelocity.MaxForce = Vector3.new(25000, 25000, 25000)
				bodyVelocity.Velocity = character.HumanoidRootPart.CFrame.lookVector * 20
				game.Debris:AddItem(bodyVelocity, 0.3)
			end
		end
	end
	wait(0.25)
	debounce = false
end

end)

1 answer

✓ Accepted answer

That is happening because at line 15, when checking if the combo is equal to 4, you set the combo variable to 5. The script continues to go down, and sees that the combo value is 5.

2 comments

0

So what should I do?

0

Nevermind I figured it out.

This discussion is preserved as it was. New answers, comments, and votes are closed.