This knockback script isn't working!

So I’m making this fighting game but there’s just one problem: this knockback/dmg script in ServerScriptService won’t work. Here’s the script:

local RmtEvent = game.ReplicatedStorage.Punch
local Dmg = game.ReplicatedStorage.Values.DmgValue.Value
local PunchSFX = game.SoundService.Punch
local BV = Instance.new("BodyVelocity")
local debounce = false

RmtEvent.OnServerEvent:Connect(function(Player, Character)
	if not debounce then
		debounce = true
	    if Character:FindFirstChild("Humanoid")then
		    Character.Humanoid:TakeDamage(Dmg)
			PunchSFX:Play()
			BV.Parent = Character.HumanoidRootPart
	    end
	    BV.MaxForce = Vector3.new(800000, 800000, 800000)
	    BV.Velocity = Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector * -40
	    wait(1)
		BV.MaxForce = Vector3.new(4000, 4000, 4000)
		BV.Velocity = Vector3.new(0, 2, 0)
		wait(0.7)
		debounce = false
	end
end)

So when I try this script, the enemy doesn’t fall back

Are there any mistakes? let me know! :smiley:

2 Likes

Greetings, the first problem is here:

Character.Humanoid:TakeDamage(Dmg)

The :TakeDamage() function can only be called from LocalScripts, you should do this instead:

Character.Humanoid.Health =  Character.Humanoid.Health - Dmg

Try to run the script with that fix and let me know!

2 Likes

This is incorrect–
Humanoid:TakeDamage works the same as humanoid.Health -= dmg.
Only difference is, if you use TakeDamage and the player has a descending ForceField, no damage will be dealt.

I use TakeDamage for my attacking server sided with no issue.

See the reference here–

1 Like

Are there any errors you can provide? If not, please use Print Debugging.
See the video roblox made–