I have 3 problems for this invisible door script:
door = script.Parent function Touch(plr) local Head = plr.Parent:FindFirstChild("Head") local Larm = plr.Parent:FindFirstChild("Left Arm") local Rarm = plr.Parent:FindFirstChild("Right Arm") local Torso = plr.Parent:FindFirstChild("Torso") local Lleg = plr.Parent:FindFirstChild("Left Leg") local Rleg = plr.Parent:FindFirstChild("Right Leg") if Larm and Rarm and Torso and Lleg and Rleg and Head ~= nil then Torso.Anchored = true door.Parent.Parent.Invisible.Name = "Turning Invisible..." wait(3) Larm.Transparency = 1 Rarm.Transparency = 1 Torso.Transparency = 1 Lleg.Transparency = 1 Rleg.Transparency = 1 Head.Transparency = 1 Head.face:remove()-- Removes your face (Btw, "face" is the name of a decal in which your head is the parent of.) Torso.Anchored = false door.Parent.Parent[Turning Invisible...].Name = "Invisible" script.Disabled = true wait(3) script.Disabled = false end end door.Touched:connect(Touch)
Problem 1# = FIXED
Problem #2 = in lines 29 - 31, they only work 1 time.
Problem #3 = When used more than once, it doesn't unanchor the plr's torso.
Don't use Disabled
to control scripts. It's a bad idea, and overly complicated.
Once the script is disabled, you can't enable it again -- it just got disabled, so it's no longer running any code.
The pattern used to accomplish pauses between events is called debounce.
It looks like this:
canDoStuff = true function Event() if canDoStuff then canDoStuff = false -- no one ELSE can do stuff -- .... -- (do the stuff) -- .... wait(3) canDoStuff = true -- I'm done, so everyone else can go now end end
You're removing an object called face
but you don't put it back. That means the second time, it tries to remove something that isn't there, and errors (read your output).
When you write something like
if width and height == 5 then
This does NOT mean "width is 5 and height is 5". The order-of-operations is
if (width) and (height == 5) then
If width
is not nil
or false
(e.g., width is probably a number), then it is truthy meaning it's "good" for an if
. Thus the above condition is the same as
if height == 5 then
You wrote
if Larm and Rarm and Head ~= nil then
when what you meant was probably
if Larm ~= nil and Rarm ~= nil and Head ~= nil then
But we know know that Larm
is either nil
or a ROBLOX object. So the ROBLOX objects are truthy, and saying ~= nil
is unnecessary:
If Larm and Rarm and Head then
(Read this as "If larm
exists, and rarm
exists, and head
exists, then...")