Hello,
So I got a door that works with a ProximityPrompt that I’d like for it to function (movement wise) as another door in my game that works with a ClickDetector. You trigger the door open and it will close by itself after 2 seconds of opened. Here’s a side by side of what they look like:
As you see, the door with the ProximityPrompt lets you open it and also close it too whenever you feel like it, however the door with the ClickDetector lets you open it as well but the only difference being that it closes by itself only and after 2 seconds, this is what I’d like for said first door to do. I’ve tried adding some of the code from the ClickDetector door to the ProximityPrompt door for the opening and closing but it didn’t really turn out as planned as I’m still decent at scripting. I’ll be providing code from the 2 doors and hopefully there’s some way to adjust things as the code is very similar:
ProximityPrompt door:
local frame = script.Parent:WaitForChild("DoorFrame")
local openSound = frame:WaitForChild("DoorOpen")
local closeSound = frame:WaitForChild("DoorClose")
local proximityprompt = frame:WaitForChild("ProximityPrompt")
local model = script.Parent
local frameClose = model:WaitForChild("DoorFrameClose")
local frameOpen = model:WaitForChild("DoorFrameOpen")
local tweenService = game:GetService("TweenService")
proximityprompt.Triggered:Connect(function()
if proximityprompt.ActionText == "Close" then
proximityprompt.ActionText = "Open"
closeSound:Play()
frame.CanCollide = true
tweenService:Create(frame,TweenInfo.new(.35),{CFrame = frameClose.CFrame}):Play()
else
proximityprompt.ActionText = "Close"
openSound:Play()
frame.CanCollide = false
tweenService:Create(frame,TweenInfo.new(.35),{CFrame = frameOpen.CFrame}):Play()
end
end)
ClickDetector door:
local frame = script.Parent
local openSound = frame:WaitForChild("DoorOpen")
local closeSound = frame:WaitForChild("DoorClose")
local clickDetector = frame:WaitForChild("ClickDetector")
local model = frame.Parent
local frameClose = model:WaitForChild("DoorFrameClose")
local frameOpen = model:WaitForChild("DoorFrameOpen")
local opened = model:WaitForChild("Opened")
local tweenService = game:GetService("TweenService")
local debounce = true
clickDetector.MouseClick:Connect(function()
if debounce == true then
debounce = false
if opened.Value == true then
opened.Value = false
tweenService:Create(frame,TweenInfo.new(0.28),{CFrame = frameClose.CFrame}):Play()
else
opened.Value = true
openSound:Play()
tweenService:Create(frame,TweenInfo.new(0.28),{CFrame = frameOpen.CFrame}):Play()
wait(2)
tweenService:Create(frame,TweenInfo.new(0.28),{CFrame = frameClose.CFrame}):Play()
end
wait(.35)
debounce = true
end
end)
I’d appreciate your help!