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

How to fix these invisible door script problems?

Asked by 9 years ago

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.

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`. BlueTaslem 18071 — 9y
0
So you mean if only the head exists, then everything else becomes invisible too? groovydino 2 — 9y
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`. BlueTaslem 18071 — 9y

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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

0
Dude, if you haven't noticed, there IS an unanchoring line. groovydino 2 — 9y
0
Oh, apologies -- you tabbed your code incorrectly there, so I skipped the line. I read the correct problem this time. BlueTaslem 18071 — 9y
Ad

Answer this question