Gun which deals knockback

I have made a gun, It works. But I want to make it so that it makes the enemy take a bit elevated knockback as well as some horizontal damage…

Here is the LOCAL SCRIPT in the tool:

local sword = script.Parent
local Rep = game:GetService("ReplicatedStorage")
local event = Rep:WaitForChild("SwordEvent")
local character = script.Parent.Parent



sword.Equipped:Connect(function(mouse)
	sword.Activated:Connect(function()
		if mouse.target.Parent:FindFirstChild("Humanoid")then
				event:FireServer(mouse.Target.Parent, 7)
		end
	end)
end)

Here is the Script in serverscriptservice:

local Rep = game:GetService("ReplicatedStorage")
local Event = Rep:WaitForChild("SwordEvent")

local function Damage(Player,Target, Damage)
	local character = Player.Character
	local ObjectHit = Target.HumanoidRootPart
	local magnitude = (character.HumanoidRootPart.Position - ObjectHit.Position).magnitude
	if magnitude < 13 then
		local EnemyHumanoid = Target:FindFirstChild("Humanoid")
		EnemyHumanoid:TakeDamage(Damage)
	end
end

Event.OnServerEvent:Connect(Damage)
2 Likes

You would need to notify the server that you dealing with knockback. Then you can simply add an onto the velocity of the HumanoidRootPart. Or create body movers. If you would like some examples just find some there are quite a few Search results for 'knockback' - DevForum | Roblox

can you explain what horizontal damage entails? are you referring to damage and knockback together it’s a strange term?

1 Like

Yes I am referring to damage and knockback together…
Like when you hit someone in minecraft they take some vertical and horizontal knockback aswell as damage

And which part of this are you having trouble with? Seems you haven’t actually responded to @Extrenious’s post about anything other than reiterating the problem.

I have no idea how to begin scripting the knockback system…

It’s not actually vertical it’s Horizontal to the attacker’s camera i assume (In Minecraft) To achieve something like that you can use CFrame | Roblox Creator Documentation to create the knockback angle using Cframe.new(Pos,LookAt)

	local Knockback_direction =  CFrame.new(Attacker, AttackReciever) 

Then you get the LookVector of the Cframe you’ve made so you can set the velocity

	local Knockback_velocity = Knockback_direction.LookVector * Force

In the end it would look something like this.

	local Force = 25 --// u can experiment with this later on 
	local Knockback_Origin = Attacker_HumanoidRootPart.Position --// The Position of attacker
	local Hit = Attack_Reciever_HumanoidRootPart.Position  --// The Position of attack reciever
	local Knockback_direction =  CFrame.new(Knockback_Origin, Attack_Reciever) 
	--// Knockback_direction would find what angle to send the character flying
			
	local Knockback_velocity = Knockback_direction.LookVector *  (25 * Force)
	local Vel = Vector3.new(ThrowinVel.X, ThrowinVel.Y + 25, ThrowinVel.Z)
	AttackReciever_Humanoid.Velocity = Vel --// Applies knock back

He doesn’t actually say he would like vertical knock back it was just the example he thought it was the case for minecraft

PLUS: My example would allow the attacker to knock the player up if they attack from below which would be vertical…

dis works mark it as solved :sob:

(weqweeqweqeqwe)