Knockback + Ragdoll is lagging

Hello everyone!

I’ve been working on a combat system for my game, but I’ve noticed that while it works (almost) perfectly on dummies, it feels laggy or delayed when applied to real players. The combat system works so it first knockbacks, waits 0.1s and ragdolls the target. I tested some things and Knockback itself works smooth, ragdoll itself works smooth but knockback + ragdoll isn’t.

Video:

Knockback script:

for _, targetParts in pairs(hitCharacter:GetDescendants()) do
	if targetParts:IsA("BasePart") and targetParts:CanSetNetworkOwnership() then
		targetParts:SetNetworkOwner(nil)
		print(targetParts)
	end
end

task.wait()

local direction = (hitCharacter.HumanoidRootPart.Position - character.HumanoidRootPart.Position).Unit
local knockbackForce = direction * 65 + Vector3.new(0, 50, 0)
hitCharacter.HumanoidRootPart.AssemblyLinearVelocity = knockbackForce

task.spawn(function()
	task.wait(.1)
	RagdollTest.Start(hitCharacter, 2)
end)

Ragdoll script:

function Ragdoll.Start(Character : Model, Duration : number)
	if Character == nil then 
		return 
	end

	local Humanoid : Humanoid = Character:WaitForChild("Humanoid")
	local RootPart = Humanoid.RootPart

	if Character:GetAttribute("Ragdolled") then
		return
	end

	local Impact : RBXScriptConnection

	Sockets[Character] = {}
	Colliders[Character] = {}
	Attachments[Character] = {}

	Character:SetAttribute("Ragdolled", true)

	local iframe = Instance.new("BoolValue", Character)
	iframe.Name = "Iframe"
	
	local stun = Instance.new("BoolValue", Character)
	stun.Name = "Stun"
	
	Humanoid.RequiresNeck = false
	Humanoid.PlatformStand = true
	Humanoid.AutoRotate = false

	for _, Item in ipairs(Character:GetDescendants()) do
		if Item:IsDescendantOf(RootPart) then 
			continue
		end

		if Item:FindFirstAncestorWhichIsA("Model") ~= Character then
			continue
		end

		if Item:IsA("Motor6D") then
			CreateCollider(Item.Part1, Character)

			Item.Enabled = false

			local Attachment0 = Instance.new("Attachment")
			Attachment0.CFrame = Item.C0
			Attachment0.Parent = Item.Part0

			local Attachment1 = Instance.new("Attachment")
			Attachment1.CFrame = Item.C1
			Attachment1.Parent = Item.Part1

			local Socket = Instance.new("BallSocketConstraint")
			Socket.Attachment0 = Attachment0
			Socket.Attachment1 = Attachment1

			Socket.LimitsEnabled = true
			Socket.UpperAngle = 30
			Socket.TwistLimitsEnabled = true
			
			Socket.Restitution = 0.1

			Socket.Parent = Item.Parent
			Sockets[Character][Item] = Socket

			table.insert(Attachments[Character], Attachment0)
			table.insert(Attachments[Character], Attachment1)
		end
	end

	if Duration ~= nil then
		task.delay(Duration, function()
			Ragdoll.Stop(Character)
		end)
	end
end

If there’s anything you could think of, I will be grateful for any help.

2 Likes

I might be wrong, could be because of player ping, I don’t know if setting the network owner nil while the player is in knock-back would work.

I don’t use setnetworkowner a lot. so, I might be entirely wrong.

2 Likes

The player’s ping might be delaying it a bit but my problem isn’t about the player’s ping. I tested on other games with the same ping and it looks much better than what I got here. And about setting the network owner to nil means the server takes over the velocity and it does look smoother for every other client. As I said the knockback is smooth, ragdoll is smooth, but both at the same time isn’t smooth.

Have you tried doing it the other way? player first then the dummy? It might be a duping problem.

If you mean about first punching the player then the dummy instead the opposite, then nope that’s not the issue neither.

Are you clearing the table when it’s done? That could make lag or delay happen, if the table isn’t being cleared

Yup, it’s in “Ragdoll.Stop” function which I haven’t show because I don’t think it’s necessary. Besides even if that was the case, It would make the dummy “lagging” too I think. I tested it for like 5 mins attacking both dummy and the player, and its always the same result.

Hm, I’m not very good at this type of stuff, I self-learn so I don’t know what a script does unless I made it.

maybe add prints for the amount of time it took.

also try a local test so you can test it against yourself and see if anything is wrong.

Nevermind, the solution to it was to first apply the ragdoll THEN the knockback, earlier I had the opposite.

1 Like

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