Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to keep dead characters?

Asked by 3 years ago

when a humanoid dies, it stays there unless its the humanoid of a character of a player. how can i make it so when a player's character dies, the dead character stays there and nothing else is affected, meaning the player would still respawn with a new character.

i looked in a lot of places, all i see is make it so the character doesnt load and it must be done manually but that isnt what i want, i still want respawning i just want the dead character to stay there forever. i tried cloning but it wont work. pls help

0
Clone the character on CharacterRemoving. radiant_Light203 1166 — 3y
0
wont work, i cnat clone AlexanderYar 788 — 3y
0
@AlexanderYar, send the script you have to clone the character on characterremoving ym5a 52 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

Not one to spoon feed. Please show us your current code to see what you have tried to do already. But anyways here you go put this as a normal Script in StarterPlayer.StarterCharacterScripts

local debrisservice = game:GetService('Debris')
local body = script.Parent
local player = game.Players:GetPlayerFromCharacter(script.Parent)
local humanoid = body:WaitForChild('Humanoid')
local bodydisposal = 30 -- Time till body is removed set to a high number if you dont want it to despawn

humanoid.Died:Connect(function()
    if player ~= nil and humanoid ~= nil then
        body.Archivable = true
        script.Parent = game:GetService("ServerScriptService")
        local cloneChar = body:Clone()
        cloneChar.Name = player.Name.."'s Deadbody"
        if game:GetService("Workspace"):FindFirstChild(cloneChar.Name) then
            game:GetService("Workspace"):FindFirstChild(cloneChar.Name):Destroy()
        end
        wait(0.1)
        cloneChar.Parent = game:GetService("Workspace")
        local rootPart = cloneChar.HumanoidRootPart or cloneChar.Torso
        local clonedHumanoid = cloneChar:FindFirstChildOfClass("Humanoid")
        cloneChar:MoveTo(rootPart.Position)
        rootPart.Orientation = Vector3.new(90,0,0)
        clonedHumanoid.PlatformStand = true
        clonedHumanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
        clonedHumanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
        for i, v in pairs(cloneChar:GetChildren()) do
            if v:IsA("BasePart") then
                v.Anchored = false
                v.CanCollide = false
            end
            if v:IsA("Script") or v:IsA("LocalScript") then
                v:Destroy()
            end
        end
        if cloneChar:FindFirstChild("ForceField") then
            cloneChar.ForceField:Destroy()
        end
        body.Parent = game:GetService("ServerStorage")
        debrisservice:AddItem(cloneChar,bodydisposal)
        debrisservice:AddItem(script,bodydisposal)
        wait(1)
        if rootPart.Orientation ~= Vector3.new(90,0,0) then
            rootPart.Orientation = Vector3.new(90,0,0)
        end
    end
end)
0
Ohh why does that work though? I already tried cloning it. AlexanderYar 788 — 3y
0
Could you explain your code to me plss AlexanderYar 788 — 3y
0
Oh right i forgot to add comments my bad but what this does is clones the character renames it and sets its parent to workspace and changes the players main character to be a different character that way the player doesn't inherite the dead body and have it despawn. so upon the player dying it adds this to the debrisservice making sure the body doesnt despawn till time is up EnzoTDZ_YT 275 — 3y
0
The first thing you said was clone, but i couldnt ever clone it trust me i used all the techniques. What makes it possible to clone it in your code? AlexanderYar 788 — 3y
0
I just figured out its because of archivable. It meanst something different than what i thought. And since characters of players have it defaukt set to false, cloning jt without making archivable true wont work! For future reference AlexanderYar 788 — 3y
Ad

Answer this question