Help with making a door

Hello Developers,

I need your help with using proximity points.

What I Need Help With

Im using a simple script I got off a tutorial. I know how the script works like 99% but I don’t want you to hold E then It opens and you then have to hold E again to close it. I want it to just open then waits 3 seconds and then it closes.

Images

Script

Location
Screen Shot 2021-02-02 at 10.12.02 AM

From,
Mista

2 Likes

Um maybe try some YouTube tutorials, there’s like a ton of them

yes I have tried them. But the problem is, is they don’t have what I want to do.

Basically if you just want it to open for 3 seconds and then close it you would have to rewrite it like this:

local ProximityPrompt = script.Parent
local Door = script.Parent.Parent

ProximityPrompt.Triggered:Connect(function()
    if ProximityPrompt.ActionText == "Open" then
        Door.Transparency = 0.5
        Door.CanCollide = false
        wait(3)
        Door.Transparency = 0 
        Door.CanCollide = true
        ProximityPrompt.ActionText = "Close"
    end
end)

Basically its just gonna wait 3 seconds and then run the close and make it nice and simple.

This isn’t working. The first part works but after the wait(…) statement it doesn’t follow.

Here you go just paste this over what you have already.

local ProximityPrompt = script.Parent
local Door = script.Parent.Parent
local Open = false

ProximityPrompt.Triggered:Connect(function()
	if not Open then
		Open = true
		Door.Transparency = 0.5
		Door.CanCollide = false
		ProximityPrompt.Enabled = false
		
		wait(3)
		
		Door.Transparency = 0 
		Door.CanCollide = true
		Open = false
		ProximityPrompt.Enabled = true
	end
end)

Do not use that code. That can lead to multiple people activating it again even when it is open.
Create a bool value inside the script and use that bool value to make sure it doesn’t activate after it is activated.

I don’t know if this is working or not however a check that it is enabled or not must be there.

local ProximityPrompt = script.Parent
local Door = script.Parent.Parent
local Bool = script.Enabled

ProximityPrompt.Triggered:Connect(function()
    if Bool.Value == false then
        Bool.Value = true
        Door.Transparency = 0.5
        Door.CanCollide = false
        wait(3)
        Door.Transparency = 0 
        Door.CanCollide = true
        Bool.Value = false
    end
end)

Also the last line of code that changes the actionname to close makes it one time use only! so i had to remove that if it was going to be reused

ok I will try this out later!

Thanks!

local ProximityPrompt = script.Parent
local Door = script.Parent.Parent
local Bool = false

ProximityPrompt.Triggered:Connect(function()
    if Bool.Value == false then
        Bool.Value = true
        Door.Transparency = 0.5
        Door.CanCollide = false
        wait(3)
        Door.Transparency = 0 
        Door.CanCollide = true
        Bool.Value = false
    end
end)

Set the bool in the script will be more organized.

Thank you! This worked!

From,
Mista