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

How would I "respawn" as myself after being morphed to something else?

Asked by 4 years ago

Hello, I am attempting to respawn my original character to my current one.

What have I done to get to this point? - I have created a morph button, changing my character to a model I put in - Changed it's name - Repositioned it to my old character's CFrame

-- Scriptwise

script.Parent.ButtonA.MouseButton1Click:Connect(function()
    local Player = game.Players:WaitForChild("bostaffmanbulgaria1")
    local OldCharacter = game.Workspace[Player.Name]:Clone()
    OldCharacter.Parent = script
    local NewChar = game.ReplicatedStorage.Dummy:Clone()
    NewChar.Name = Player.Name
    NewChar:SetPrimaryPartCFrame(game.Workspace[Player.Name]:FindFirstChild("HumanoidRootPart").CFrame + Vector3.new(0, 5, 0))
    Player.Character = NewChar
    NewChar.Parent = game.Workspace
end)

**What I am trying to accomplish? **

I'm trying to revert my old character back in the same way as I morphed it.

What I have done so far? - Cloned my old character before any code regarding character change being ran - result: ERROR: Players.bostaffmanbulgaria1.PlayerGui.ScreenGui.Script:4: attempt to index nil with 'Parent'

I did **not ** find any information about this in Google.

2 answers

Log in to vote
1
Answered by 4 years ago

Characters by default are not archivable. That means you cannot clone them neither save a copy of them if their archivable property is set to false.

To do this you have to set it's Archivable property to true

Character.Archivable = true

Implementing this into your code

script.Parent.ButtonA.MouseButton1Click:Connect(function()
    local Player = game.Players:WaitForChild("bostaffmanbulgaria1")
    local Character = workspace[Player.Name]
    Character.Archivable = true
    local OldCharacter = Character:Clone()
    OldCharacter.Parent = script
    local NewChar = game.ReplicatedStorage.Dummy:Clone()
    NewChar.Name = Player.Name
    NewChar:SetPrimaryPartCFrame(game.Workspace[Player.Name]:FindFirstChild("HumanoidRootPart").CFrame + Vector3.new(0, 5, 0))
    Player.Character = NewChar
    NewChar.Parent = game.Workspace
end)

I also recommend to use FindFirstChild() instead of game.Workspace[Player.Name] and also use workspace instead of game.Workspace

If that answered your question mark it as the answer!

0
Thanks a lot. I never thought of the Archivable property to be disabled. bostaffmanbulgaria1 89 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

try making it a while true do loop, (but remember, put a wait() in there or it will break!)

Answer this question