Help me make a knockback script

I need help making a knockback for the hitbox

I made one but it didn’t work on players it only worked on dummys:

game.ReplicatedStorage.MainEvent.OnServerEvent:Connect(function(player)
task.spawn(function()
player.Character.Humanoid.WalkSpeed = 7
task.wait(.35)
player.Character.Humanoid.WalkSpeed = 16
end)
local HitBox = Instance.new(“Part”)

HitBox.Parent = workspace
HitBox.CanCollide = false
HitBox.Anchored = true
HitBox.Size = Vector3.new(5,7,5)
HitBox.BrickColor = BrickColor.new("Really red")
HitBox.Transparency = 1
HitBox.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-2.5)
game.Debris:AddItem(HitBox, 1)





local hitboxCoolDown = false

HitBox.Touched:Connect(function(hit)
   if hit.Parent.Name ~= player.Name and hit.Parent:FindFirstChild("Humanoid") then
		if hitboxCoolDown == true then return end
		hitboxCoolDown = true 
		
		
		
		hit.Parent:FindFirstChild("Humanoid"):TakeDamage(5)
		game.Workspace["Cartoon punch sound effect"]:Play()
		
		local anim = hit.Parent:FindFirstChild("Humanoid"):LoadAnimation(game.ReplicatedStorage.Ouch)
		anim:Play()
		game.Debris:AddItem(anim,2)
		
		
		task.wait(1)


		hitboxCoolDown = false
		
   end
   	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent:FindFirstChild("Humanoid").Died:Connect(function()
			player.leaderstats.Points.Value = player.leaderstats.Points.Value + 1
		end)
   	end
	


end)

end)

1 Like

Sounds like issues with network ownership, you probably ran that script on the server. So try applying body velocity on the humanoid root part for knockback and set the part’s network owner to nil so that the server’s changes actually apply. After a small delay, do hrp:SetNetworkOwnershipAuto() to set it back to the player

old knockback, maybe you can pick out what you need.

--SeverScript inside a part.

local bv, char
local db = true
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		if db then db = false char = hit.Parent
			bv = Instance.new("BodyVelocity")
			bv.Parent = (char.Head)
			bv.MaxForce = Vector3.new(100000,100000,100000)
			bv.Velocity = (char.Head.CFrame.LookVector * -80)
				+ (char.Head.CFrame.UpVector * 80)
			wait(0.01) bv:Destroy()
			db = true
		end
	end
end)

Bodyvelocity had been deprecated

Well, did you try using it though?

Body velocity has been deprecated

No I haven’t yet but I used apply impulse after I found out bodyvelocity isn’t used any more it still did not work

Hmm … how about like this.

local db = true
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if db then db = false
			local char = hit.Parent
			local head = char:FindFirstChild("Head")
			local hrp = char:FindFirstChild("HumanoidRootPart")
			if head and hrp then
				local lookDirection = head.CFrame.LookVector

				local force = Instance.new("VectorForce")
				force.Parent = hrp
				force.Attachment0 = hrp:FindFirstChild("RootAttachment") or Instance.new("Attachment", hrp)
				force.ApplyAtCenterOfMass = true
				force.RelativeTo = Enum.ActuatorRelativeTo.World

				force.Force = (lookDirection * -10000) + Vector3.new(0, 8000, 0)
				task.wait(0.1) force:Destroy()
			end	db = true
		end
	end
end)

You need to try the Search button up top. This question has been solved so many times in other posts.
I did a quick search using the words knockback pushback and found a lot of previous posts.

What’s it take to answer this …

HitBox.Parent = workspace
HitBox.CanCollide = false
HitBox.Anchored = true
HitBox.Size = Vector3.new(5,7,5)
HitBox.BrickColor = BrickColor.new("Really red")
HitBox.Transparency = 1
HitBox.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-2.5)
game.Debris:AddItem(HitBox, 1)

local hitboxCoolDown = false

HitBox.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid and hit.Parent.Name ~= player.Name then
        if hitboxCoolDown then return end
        hitboxCoolDown = true
        
        humanoid:TakeDamage(5)
        game.Workspace["Cartoon punch sound effect"]:Play()

        local anim = humanoid:LoadAnimation(game.ReplicatedStorage.Ouch)
        anim:Play()
        game.Debris:AddItem(anim, 2)

        local char = hit.Parent
        local head = char:FindFirstChild("Head")
        local hrp = char:FindFirstChild("HumanoidRootPart")
        if head and hrp then
            local lookDirection = head.CFrame.LookVector

            local force = Instance.new("VectorForce")
            force.Parent = hrp
            force.Attachment0 = hrp:FindFirstChild("RootAttachment") or Instance.new("Attachment", hrp)
            force.ApplyAtCenterOfMass = true
            force.RelativeTo = Enum.ActuatorRelativeTo.World

            force.Force = (lookDirection * -10000) + Vector3.new(0, 8000, 0)
            task.wait(0.1)
            force:Destroy()
        end

        task.wait(1)
        hitboxCoolDown = false
    end
    
    if humanoid then
        humanoid.Died:Connect(function()
            player.leaderstats.Points.Value = player.leaderstats.Points.Value + 1
        end)
    end
end)
2 Likes

I tried a similar way like this but Ill try the alternative, i haven’t tested it on players yet but it worked for dummys ill let you if it works or not thanks

other thing, I notice you directly put animations on the humanoid which is bad practice. I would recommend going humanoid.Animator:LoadAnimation(animation id)

Hey, the first method works! All I have to do is increase its force and I’ll test the second method

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.