Ad
Log in to vote
0

How do i make ragdoll show on other players perspective?

Asked by 6 days ago
local Storage = game.ReplicatedStorage
local ragdollDummy = Storage.Ragdoll_Rig
local debounce = false
local Players = game:GetService("Players")
local DebrisMoment = game:GetService("Debris")

local function safeClone(instance)
    local oldArchivable = instance.Archivable

    instance.Archivable = true
    local clone = instance:Clone()
    instance.Archivable = oldArchivable

    return clone
end

game.Players.PlayerAdded:Connect(function(p)
    p.CharacterAdded:Connect(function(c)
        repeat wait() until p.Character
        print("character respawned")
        local hum = c:WaitForChild("Humanoid")

        hum.Died:Connect(function()
            print("character died beginning ragdoll")
            --if debounce then return end
            --debounce = true
            local newCharacter = safeClone(ragdollDummy)
            local ragdollHumanoid = newCharacter:FindFirstChild("Humanoid2")

            DebrisMoment:AddItem(newCharacter, 300) -- timer

            newCharacter.Name = "Ragdolled "..p.Name
            ragdollHumanoid.PlatformStand = true

            --makes the ragdoll look like the player
            for _, v in pairs(c:GetChildren()) do
                if v:IsA("Shirt") or v:IsA("Pants") or v:IsA("ShirtGraphic") or v:IsA("Accessory") or v:IsA("BodyColors") then
                    safeClone(v).Parent = newCharacter
                end
            end

            newCharacter.Parent = workspace.Debris
            --newCharacter.Name = plr..

            --makes the ragdoll go to where the player is and retains the velocity
            for _, v in pairs(newCharacter:GetChildren()) do
                for _, x in pairs(c:GetChildren()) do
                    if v.Name == x.Name then
                        if v:IsA("BasePart") and x:IsA("BasePart") then
                            v.CFrame = x.CFrame
                            v.Velocity = x.Velocity
                            v.RotVelocity = x.RotVelocity
                        end
                    end
                end
            end

            --deletes the player and prevents warnings from roblox.
            --[[for _, v in pairs(c:GetDescendants()) do
                if v:IsA("BasePart") then
                    v:Destroy()
                end
            end-]]

            print("works")

            p.CharacterRemoving:Connect(function()
            end)
        end)
    end)
end)

For some reason the ragdoll works for a few deaths and just stops working completely. It's a local script, it doesn't work as a serverscript. it works the best in StarterGUI. No, putting it as a serverscript doesn't work, no putting it inside startercharacterscripts doesn't work.

0
You Could Try Remote Events Magicdevice3 28 — 6d

Answer this question