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

How to receive parts that is nil back?

Asked by 6 years ago

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)

0
Why set it's parent to nil? There's easier ways to do this. oftenz 367 — 6y
0
what's that? MArzalAlBuchariZ 33 — 6y

1 answer

Log in to vote
1
Answered by
aschepler 135
6 years ago

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.

Ad

Answer this question