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