Long delay with ragdoll in my combat system

Hello, I am making a combat system, and currently, I have a lag issue with ragdoll (yes I’m going to make the kick distance smaller). To prevent lag issues with the velocity of the target I’m setting the network ownership of the target to the server (nil). But I have issues with ragdoll.

I’ve tried using coroutine for the region3 part of the script, but I didn’t see any fixes. Without ragdoll, it works just fine. Even with the alternative wait() function, it didn’t help.

Here’s the issue

The part where the script is damaging the player

local Player1 = Players:GetPlayerFromCharacter(self.Character)
local Player2 = Players:FindFirstChild(Part.Parent.Name)

local Humanoid = Part.Parent.Humanoid

Humanoid:TakeDamage(Damage)
DamageIndicator:FireClient(Player1, Part.Parent, Damage, Humanoid.MaxHealth)

self.HeartBeatConnection:Disconnect()

if Player2 then
	Part.Parent.HumanoidRootPart:SetNetworkOwner(nil)

	Part.Parent.HumanoidRootPart.Velocity = self.Character.HumanoidRootPart.CFrame.LookVector * 100 + self.Character.HumanoidRootPart.CFrame.UpVector * 40

	wait(0.5)

	Effects:RagDollState(Player2, Part.Parent, true)

	wait(1)

	Effects:RagDollState(Player2, Part.Parent, false)
end

Part of the ragdoll function

for _, Object in pairs(Character:GetDescendants()) do
	if Object:IsA("Motor6D") then
		if Object.Name ~= "Root" and Object.Name ~= "RootJoint" and Character.Joints:FindFirstChild(Object.Name) then
			local Attachment0 = Instance.new("Attachment")
			Attachment0.Name = "RagdollSocket"
			Attachment0.CFrame = Object.C0
			Attachment0.Parent = Object.Part0
			local Attachment1 = Instance.new("Attachment")
			Attachment1.Name = "RagdollSocket"
			Attachment1.CFrame = Object.C1
			Attachment1.Parent = Object.Part1

			local Socket = Character.Joints:FindFirstChild(Object.Name)
			Socket.Attachment0 = Attachment0
			Socket.Attachment1 = Attachment1
			Socket.Enabled = true

			Object.Enabled = false
		end
	end
end

Character.HumanoidRootPart.CanCollide = false
Character.HumanoidRootPart.Massless = true

ChangeState:FireAllClients(Character, Enum.HumanoidStateType.Physics)

Big thanks for reading this :grinning:

2 Likes

After a deeper research I’ve found that the issue was in the network ownership, with it there were less lag in the studio, but after testing it in-game without server network ownership it had no lag, that means this post was useless lol

6 Likes

Could you help me with mine? I’ve been working for day trying different things but none of them would work