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

Will these button doors work?[NEEDS TO BE CHECKED AGAIN]

The first script says that when someone steps on a brick called Button, another brick called Door will become transparent and walkthrough. The second one says that when someone clicks a part called Button, the part called Door will open. Will these work? [EDITED BY DUMMIEZ]

First script (Button Touch Door)

local debounce = true
function onTouch(Button)
if debounce and Button.Parent:FindFirstChild("Humanoid") and Button.Parent.Name == game.Players:findFirstChild(Button.Parent.Name) then debounce = false
game.Workspace.Door.Transparency = 0.5
game.Workspace.Door.CanCollide = false
wait(5)
game.Workspace.Door.Transparency = 0
game.Workspace.Door.CanCollide = true
debounce = true
end end
 
script.Parent.Touched:connect(onTouch)

Second script (Button Click Door)

H = game.Workspace.Door

local debounce = true
function onTouch(Button)
if debounce and Button.Parent:FindFirstChild("Humanoid") and Button.Parent.Name == game.Players:findFirstChild(Button.Parent.Name) then debounce = false
function onClick(Button)
H.Transparency = 0.5
H.CanCollide = false
wait(5)
H.Transparency = 0
H.CanCollide = true
end end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 answer

✓ Accepted answer

These should work fine, however some improvements in the first script with Touched events, is that if you want only players or humanoids to active the door is to check if parent contains a Humanoid or search for the name on thegame.Players

First script:

local debounce = true
function onTouch(Button)
if debounce and Button.Parent:FindFirstChild("Humanoid") and Button.Parent.Name == game.Players:findFirstChild(Button.Parent.Name) then debounce = false
game.Workspace.Door.Transparency = 0.5
game.Workspace.Door.CanCollide = false
wait(5)
game.Workspace.Door.Transparency = 0
game.Workspace.Door.CanCollide = true
debounce = true
end end

script.Parent.Touched:connect(onTouch)

You can do the debounce with the second door as well.

3 comments

0

Thank you Dummiez :D

0

I edited the first and second scripts

0

Yes these should work, make sure to put debounce = true in the second script or else it will always be false.

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