Knockback force works perfectly on non player characters, but as soon as I try and use it on players it ceases to function

I am trying to make a knockback system that effects both players and characters. However, it just has no effect on players, and it doesn’t throw any errors.

Here is the code snippet I use to add the momentum:

Char2.HumanoidRootPart.AssemblyLinearVelocity += Char1.HumanoidRootPart.CFrame.LookVector * 195

(Char1 refers to the character applying the knockback, char2 refers to the one receiving it.)
No clue why it simply refuses to function. All characters are r6, and have all extra parts set on massless.

Use BodyVelocity, works fine even though its deprecated

Network ownership and humanoids usually, testing file and video showcase is here:

Do this on a LocalScript for characters. Or, set the network owner to the server for a very short time. Worked fine for me when I made BaseAdmin’s fling command.

Even after setting network ownership it still wants to not work.

warn('Attempt to apply knockback')
				Combat.Content.SetToServer(Char2,2)
				Char2.Humanoid.PlatformStand = true
				local trollFling = Vector3.new(-1,0,0)*50+Vector3.new(0,1,0)*25
				Char2.HumanoidRootPart.AssemblyLinearVelocity += trollFling
				warn('did it')
				task.wait(0.3)
				Char2.Humanoid.PlatformStand = false

(Copied troll fling from provided example to see if it was a velocity problem)
Here’s the set ownership to server script.

['SetToServer'] = function(Char,Time)
		local check = Players:GetPlayerFromCharacter(Char)
		if check and true == false then
			Char.HumanoidRootPart:SetNetworkOwner(nil)
			task.wait(Time)
			Char.HumanoidRootPart:SetNetworkOwner(check)
		end
	end,

If it helps, here is the code from BaseAdmin.

t.fling = {function(Player, plr)
	for _, p in pairs(getPlayerRun(Player, plr)) do
		if p.Character then
			local pp = p.Character.PrimaryPart
			if pp then
				local h = p.Character:FindFirstChildWhichIsA("Humanoid")
				if h then
					h.Sit = true
				end
				pp:SetNetworkOwner()
				pp.AssemblyLinearVelocity += Vector3.new(200, 200, 0)
				delay(1, function()
					pp:SetNetworkOwnershipAuto()
				end)
			end
		end
	end
end, "Fling", '<plr>', 2}

Edit: I noticed your problem is that you did not set the network owner back to the player in a separate thread, so it will yield the current thread.

1 Like

I don’t set the ownership back in separate thread? Would it be possible for slight elaboration? Should I have a separate function to set ownership back?

If you don’t set ownership back in a separate thread, it will set it to the server and set it back and then add velocity. You need to add velocity while it is on the server or else it will not work.

1 Like

Thank you. YOu have saved me. I am very grateful.

1 Like