Lag And Delay when Un-ragdolled NPC

There’s lag when the NPC unragdolls And i dont know what it causes it

Untitled Gamesd - Roblox play the game to understand

In studio Works Fine, but testing it in the Normal launcher it causes this problem

My current Script that is On ServerScriptService

wait(0.25)

local replicated = game:GetService("ReplicatedStorage")
local storage = game:GetService("ServerStorage")
local rakedoll = storage:WaitForChild("RakeStunned")

local remote = replicated:WaitForChild("StunEvent")
local ragdolltime = rakedoll:WaitForChild("StunTime")
local isragdolled = false

function ragdoll()
		if workspace:FindFirstChild("Rake") then
			print("Ragdolled Rake")
	        local clone = rakedoll
		clone.Parent = workspace
		wait()
		for i, v in pairs(clone:GetChildren()) do
			if v:IsA("BasePart") then
				v.CFrame = workspace.Rake.HumanoidRootPart.CFrame
			end
		end
	       wait(0.1)
           workspace.Rake.Parent = storage
			
	    
    end
end


function unragdoll()
	if not workspace:FindFirstChild("Rake") then
			print("Unragdolled Rake")
			if storage:FindFirstChild("Rake") and workspace:FindFirstChild("RakeStunned") then
			storage.Rake.Parent = workspace
			wait(0.1)
				workspace.RakeStunned.Parent = storage
			end
		end
	end

remote.Event:Connect(function(player)--, dmg, ragdolltime)
	--print("Rake Stunned")
	ragdolltime.Value = math.random(6,7)
	ragdoll()
	repeat wait(1) ragdolltime.Value -= 1 until ragdolltime.Value <= 0
	  unragdoll()
end)

Sets the RagdollStunned parent to workspace and changes his position to the original Killer Pos
Also waits the timer to finish and Unragdolls

The main issue I am thinking of is, you position the Rake at the same position around where the StunnedRake doll is at, this will make both collide which each other, so instead you have to “remove” the stunned rake first then “add” the original rake.
So:

workspace.RakeStunned.Parent = storage
--wait(.1) -- only add this if it stays laggy.
storage.Rake.Parent = workspace

Note, that you might need to set the HumanoidRootCFrame to that of the StunnedRake, though this could make it so that the rake needs a second to stand up.

Another “issue” I suggest you would change is, that you are using the original “rakedoll”

local clone = rakedoll

use

local clone = rakedoll:Clone()

then instead of reparenting the doll, destroy it

workspace.RakeStunned:Destroy()

Thanks for the help , I’ll try and notice you

sadly its still a bit too lag…