How to make a less laggy and better knockback

hello im trying to make a less laggy knockback, someone told me i sould use vectorforce but is so hard to work on + i new with vectorforce, so is there other option? that i sould use???.

btw here the script that made the knockback (“velf” and “veltime” are arguments that set the values so dont worry about them)

		local KnockBack = Instance.new("BodyVelocity",enemy:FindFirstChild("HumanoidRootPart"))
		KnockBack.MaxForce = Vector3.new(math.huge,0,math.huge)
		KnockBack.Velocity = player.Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector * velf

		local KnockBack2 = Instance.new("BodyVelocity", player.Character:FindFirstChild("HumanoidRootPart"))
		KnockBack2.MaxForce = Vector3.new(math.huge,0,math.huge)
		KnockBack2.Velocity = player.Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector * velf

		game.Debris:AddItem(KnockBack, veltime)	
		game.Debris:AddItem(KnockBack2, veltime)
4 Likes

The script you provided above is perfectly fine, though if you wanted to reduce lag, you should put this on the client if it wasn’t or you could use apply impulse to deal knockback as well.

assuming you want a “knockback” system for combat i’m assuming. This script uses the CFrame of 2 humanoid root parts.
short example use of :ApplyImpulse() using 2 CFrames:

local knockback = function(humanoidrootpart, enemy_humanoidrootpart, force)
force = force or 10
enemy_humanoidrootpart:ApplyImpulse((-humanoidrootpart.CFrame.LookVector) * force) 
end

Hope this helped, and if you could clarify; What do you mean by laggy?

5 Likes

the method doesnt really matter its all the same but if you want no lag it should be done on the client

4 Likes

first up, yes indeed is for combat system, and second is indeed on server side my script and i really scared to switch to client side cuz, exploiters and i dont really know how to make anti cheat code to prevent exploiters use that function, and thrid of all, this is what im refer by laggy:
(when spawning):

(after some seconds or 1 minute):

ima try the script you made so later ima say the results of that

2 Likes

mmh, yea ima try do client, but still scared about the exploiters access to that script

2 Likes

If you still want to do it on the Server, maybe try setting the network ownership part to the player?

Of course, this comes with a major flaw, that being that this only fixes the lag on one client-screen

To go about fixing this I would just go on the client, as that is the only solution I see.

ex:

	local KnockBack = Instance.new("BodyVelocity",enemy:FindFirstChild("HumanoidRootPart"))
		KnockBack.MaxForce = Vector3.new(math.huge,0,math.huge)
		KnockBack.Velocity = player.Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector * velf

		local KnockBack2 = Instance.new("BodyVelocity", player.Character:FindFirstChild("HumanoidRootPart"))
		KnockBack2.MaxForce = Vector3.new(math.huge,0,math.huge)
		KnockBack2.Velocity = player.Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector * velf
                
        player.Character:FindFirstChild("HumanoidRootPart"):SetNetworkOwnership(player)

		game.Debris:AddItem(KnockBack, veltime)	
		game.Debris:AddItem(KnockBack2, veltime)

One non-exploitable solution that I just came to think of and MIGHT NOT WORK (feel free to test)
is to set the network ownership on client (which I have NO IDEA whether it is possible or not, technically speaking it probably isn’t.)

To do this you would send fire the part to all clients with a remote event, then change the network ownership to that part.

Keep in mind: There’s an 80% chance this idea won’t work

3 Likes

you can’t set network ownership of a part on the client

A shame… Oh well, seems the only solution is to put it on the client.

2 Likes

sorry for being unactive, but i have an idea, i could make a metatable, and make a whole system to make forces, body part, etc. in client side, but i have this issue, that if i make the metatable in server side, and the metatable fires a remote event (fireallclients), can be still laggy?, i know is a dumb question but, talking about if is laggy when the instance is created.
should i make the whole system in client side? (module script where is the metatable).

1 Like