What Is the best way to go about this?

Hello everyone,

i was making a ragdoll system and wanted to make an optimized way to have it be triggered by an attribute and then, after a duration, the ragdoll deactivates. This is a combat script, so i dont want it to be all on the attackers side, because if they left, the victim would be stuck in ragdoll forever! the best thing i’ve had so far is below, the script’s parent is a rig(hint, it doesn’t work):

while true do
 repeat 
  task.wait()
 until Humanoid:GetAttribute("IsRagdolled")
require(Module).StartRagdoll(Humanoid)
repeat 
 task.wait()
until tick() - Humanoid:GetAttribute("LastRagdoll") > 3
Humanoid:SetAttribute("IsRagdolled", false)
require(Module).StopRagdoll(Humanoid)
end

this is terrible. someone please tell me how to make a better version of this…

local Module = require(Module)
while true do
    Humanoid:GetAttributeChangedSignal("IsRagdolled"):Wait()
    Module.StartRagdoll(Humanoid)
    task.wait(math.abs(Humanoid:GetAttribute("LastRagdoll") - tick() + 3))
    Humanoid:SetAttribute("IsRagdolled", false)
    Module.StopRagdoll(Humanoid)
end

Should work and be more optimized

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