Got a little trouble with knockback

I want to create a knockback system. For some reason, whenever I knock a player back, the knockback is not displayed on the attacker’s side, but only the resulting position. The knockback is perfect for the player being knocked back.
This is a video of what I’m talking about:
https://streamable.com/mwjtvc

I’m using FireAllClients (as shown by the red highlight), so I really don’t understand what the problem is.
This is the server code:

v.Parent:FindFirstChild("Humanoid").PlatformStand = true
		fm1de:FireAllClients(player, v)
		v.Parent:WaitForChild("HumanoidRootPart").Orientation = player.Character.HumanoidRootPart.Orientation - Vector3.new(0,180,0)
		hit:Play()
		v.Parent:FindFirstChild("Humanoid"):TakeDamage(5)
		v.Parent:FindFirstChild("Humanoid").WalkSpeed = 0
	--	for index, joint in pairs(v.Parent:GetDescendants()) do
	--		task.spawn(function() -- I put the SPAWN function here instead
	--			if joint:IsA('Motor6D') then
	--				local socket = Instance.new('BallSocketConstraint')
	--				local a1 = Instance.new('Attachment')
	--				local a2 = Instance.new('Attachment')
	--				a1.Parent = joint.Part0
	--				a2.Parent = joint.Part1
	--				socket.Parent = joint.Parent
	--				socket.Attachment0 = a1
	--				socket.Attachment1 = a2
	--				a1.CFrame = joint.C0
	--				a2.CFrame = joint.C1
	--				socket.LimitsEnabled = true
	--				socket.TwistLimitsEnabled = true
	--				joint.Enabled = false
	--				task.wait(1)
					v.Parent:FindFirstChild("Humanoid").PlatformStand = false
				v.Parent:FindFirstChild("Humanoid").WalkSpeed = 10

And the local code:

fm1de.OnClientEvent:Connect(function(player, v)
	local mark = Instance.new("Highlight", player.Character)
	v.Parent:FindFirstChild("Humanoid").AutoRotate = false
	local knockbackdir = player.Character.HumanoidRootPart.CFrame.LookVector
	local bg = Instance.new("BodyGyro")
	bg.Parent = v.Parent:WaitForChild("HumanoidRootPart")
	bg.D = 0
	bg.P = 500000
	bg.CFrame = CFrame.lookAt(v.Parent:WaitForChild("HumanoidRootPart").Position, knockbackdir)
	local att = Instance.new("Attachment")
	att.Parent = v.Parent:WaitForChild("HumanoidRootPart")
	local vf = Instance.new("VectorForce")
	vf.Parent = v.Parent:WaitForChild("HumanoidRootPart")
	vf.Attachment0 = att
	vf.Force = Vector3.new(0,5000,10000)
	for index, joint in pairs(v.Parent:GetDescendants()) do
		task.spawn(function() -- I put the SPAWN function here instead
			if joint:IsA('Motor6D') then
				local socket = Instance.new('BallSocketConstraint')
				local a1 = Instance.new('Attachment')
				local a2 = Instance.new('Attachment')
				a1.Parent = joint.Part0
				a2.Parent = joint.Part1
				socket.Parent = joint.Parent
				socket.Attachment0 = a1
				socket.Attachment1 = a2
				a1.CFrame = joint.C0
				a2.CFrame = joint.C1
				socket.LimitsEnabled = true
				socket.TwistLimitsEnabled = true
				joint.Enabled = false
				task.wait(0.1)
				v.Parent:FindFirstChild("Humanoid").AutoRotate = true
				vf:Destroy()
				bg:Destroy()
				att:Destroy()
				task.wait(0.75)
				v.Parent:FindFirstChild("Humanoid").PlatformStand = false
				v.Parent:FindFirstChild("Humanoid").WalkSpeed = 10
				joint.Enabled = true
				socket:Destroy()
			end
		end)
	end
end)

Any help would be greatly appreciated.

3 Likes

You’re experiencing a NetworkOwnership problem, which is why you should be adding the BodyVelocity on the server.

Server code:

v.Parent:FindFirstChild("Humanoid").PlatformStand = true
fm1de:FireAllClients(player, v)
v.Parent:WaitForChild("HumanoidRootPart").Orientation = player.Character.HumanoidRootPart.Orientation - Vector3.new(0,180,0)
hit:Play()

local knockbackdir = player.Character.HumanoidRootPart.CFrame.LookVector

local bg = Instance.new("BodyGyro")
bg.D = 0
bg.P = 500000
bg.CFrame = CFrame.lookAt(v.Parent:WaitForChild("HumanoidRootPart").Position, knockbackdir)
bg.Parent = v.Parent:WaitForChild("HumanoidRootPart")

local att = Instance.new("Attachment")
att.Parent = v.Parent:WaitForChild("HumanoidRootPart")

local vf = Instance.new("VectorForce")
vf.Attachment0 = att
vf.Force = Vector3.new(0,5000,10000)
vf.Parent = v.Parent:WaitForChild("HumanoidRootPart")

v.Parent:FindFirstChild("Humanoid"):TakeDamage(5)
v.Parent:FindFirstChild("Humanoid").WalkSpeed = 0

Client code:

fm1de.OnClientEvent:Connect(function(player, v)
	local mark = Instance.new("Highlight", player.Character)
	v.Parent:FindFirstChild("Humanoid").AutoRotate = false

	for index, joint in v.Parent:GetDescendants() do
		if joint:IsA('Motor6D') then
			local socket = Instance.new('BallSocketConstraint')
			local a1 = Instance.new('Attachment')
			local a2 = Instance.new('Attachment')
			a1.Parent = joint.Part0
			a2.Parent = joint.Part1
			socket.Parent = joint.Parent
			socket.Attachment0 = a1
			socket.Attachment1 = a2
			a1.CFrame = joint.C0
			a2.CFrame = joint.C1
			socket.LimitsEnabled = true
			socket.TwistLimitsEnabled = true
			joint.Enabled = false
			
			task.delay(0.1, function()
				v.Parent:FindFirstChild("Humanoid").AutoRotate = true
				vf:Destroy()
				bg:Destroy()
				att:Destroy()
				task.wait(0.75)
				v.Parent:FindFirstChild("Humanoid").PlatformStand = false
				v.Parent:FindFirstChild("Humanoid").WalkSpeed = 10
				joint.Enabled = true
				socket:Destroy()
			end)
		end
	end
end)

Thanks for the response. Unfortunately, it did not change anything about the knockback. I want to think that it has something to do with the ragdoll script? I don’t know though.

1 Like

Did you ever figure it out? I’ve been struggling with a similar issue, in which making knockback seems delayed on both clients, but normal on the server.

Nope. Sorry to be the bearer of bad news.

Haha no worries man, the delay isn’t the worst at the end of the day, and the game still functions so im okay with it

Have you tried creating the ragdoll on the server?

Yes. I did that with an R6 dummy that was made specifically as a dummy in the game. Since it has no client, it’s knockback must obviously be on the server. Thing is, despite the knockback working perfectly, there’s about a half-second delay for it to actually happen.