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

How do I make this door stop letting Players interact with it after a while?

Asked by
EpicLilC 150
8 years ago

So I was messing around with functions and names, so I made a script so that a door that named "DANK"(because I wanted the script or whatever to locate that only) would become locked, after the player touches it, slowly fade away using transparency, then make it so the player can walk through it, and last, make it so the player can't walk through it. My problem is, every time I touch the door again, the transparency goes crazy. How do I fix this? Here's the script.

function onTouch()
    wait(.3)
    workspace.DANK.Locked = true
    wait(1)
    workspace.DANK.Transparency= .3
    wait(1)
    workspace.DANK.Transparency= .5
    wait(1)
    workspace.DANK.Transparency =.6
    wait(1)
    workspace.DANK.Transparency=.8
    wait(1)
    workspace.DANK.Transparency=1
    wait(1)
    workspace.DANK.Transparency=0
    wait(1)
    workspace.DANK.CanCollide= false
    wait(3)
    workspace.DANK.CanCollide=true
    print'the script works m8'
end
game.Workspace.DANK.Touched:connect(onTouch)

1 answer

Log in to vote
1
Answered by
obcdino 113
8 years ago

You need a debounce for your door, preventing the player from touching it too many times.

Basically, it makes sure that if the player touches it and the debounce is still running, it won't do the function by returning end.

FINAL SCRIPT:

debounce = false
function onTouch()
    if debounce then return end
    wait(.3)
    workspace.DANK.Locked = true
    wait(1)
    workspace.DANK.Transparency= .3
    wait(1)
    workspace.DANK.Transparency= .5
    wait(1)
    workspace.DANK.Transparency =.6
    wait(1)
    workspace.DANK.Transparency=.8
    wait(1)
    workspace.DANK.Transparency=1
    wait(1)
    workspace.DANK.Transparency=0
    wait(1)
    workspace.DANK.CanCollide= false
debounce = true -- Prevents multiple touches while running.
    wait(3)
    workspace.DANK.CanCollide=true
    print'the script works m8'
debounce = false -- Allows the user to touch it once again.
end
game.Workspace.DANK.Touched:connect(onTouch)

Ad

Answer this question