Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to receive parts that is nil back?

I'm trying to make my custom character transform when the player press e, and it will go back to its original from by pressing e again, but it kept saying: The Parent property of Leg1 is locked, current parent: NULL, new parent ---- is anything wrong here?

local KeyPressed = 0

game:GetService("UserInputService").InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.E then -- if e is pressed one time, it will set the part listed below nil
	KeyPressed = 1
       L1:Destroy()
L1.Parent = nil
L2.Parent = nil
L12.Parent = nil
L22.Parent = nil
S1.Parent = nil
S2.Parent = nil
Animate.Parent = nil
Humanoid.HipHeight = 1
   end
end)

game:GetService("UserInputService").InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.E then -- if e is pressed again, it will set the part back to the character
	KeyPressed = 2
L1.Parent = script.Parent
L2.Parent = script.Parent
L12.Parent = script.Parent
L22.Parent = script.Parent
S1.Parent = script.Parent
S2.Parent = script.Parent
Animate.Parent = script.Parent
Humanoid.HipHeight = 10
   end
end)

2 comments

0

Why set it's parent to nil? There's easier ways to do this.

0

what's that?

1 answer

✓ Accepted answer

Destroy can't be undone, and one of the things it does is lock the Parent property so it can't be put back in the game.

So take out your L1:Destroy() line. The parts setting Parent properties to nil is enough to get the parts temporarily out of the game.

This discussion is preserved as it was. New answers, comments, and votes are closed.