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

How to fix these invisible door script problems?

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.

3 comments

0

A warning: Line 12 doesn't mean what you think it means (though it still happens to be correct) -- the ~= nil only applies to the head.

0

So you mean if only the head exists, then everything else becomes invisible too?

0

No, it will behave correctly. It's redundant to say ~= nil. If it's nil, it acts like false; actual parts will act like true, so the ~= nil is unnecessary. I am just commenting that a and b ~= nil is NOT the same thing as a ~= nil and b ~= nil.

1 answer

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).


How "and" works

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...")

2 comments

0

Dude, if you haven't noticed, there IS an unanchoring line.

0

Oh, apologies -- you tabbed your code incorrectly there, so I skipped the line. I read the correct problem this time.

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