local doorPart = game.Workspace:WaitForChild(“DoorPart”)
local openSound = doorPart:WaitForChild(“OpenSound”)
local closeSound = doorPart:WaitForChild(“CloseSound”)
local isOpen = false
local canOpen = true
--------- Cooldown Door Settings ---------
local cooldownTime = 10
local lastOpenTime = 0
local openPosition = doorPart.Position + Vector3.new(0, 8, 0)
local closedPosition = doorPart.Position
local doorStayOpenTime = 5
--------- Door Distance Settings ---------
local proximityDistance = 10
local function OpenDoor()
local currentTime = tick()
print(“Attempting to open the door…”)
if not isOpen and canOpen and (currentTime - lastOpenTime >= cooldownTime) then
local tweenInfo = TweenInfo.new(2.5)
--------- Tween Door Open Settings ---------
local tween = game:GetService("TweenService"):Create(doorPart, tweenInfo, {Position = openPosition})
tween:Play()
local randomPlaybackSpeed = math.random(90, 110) / 100
openSound.PlaybackSpeed = randomPlaybackSpeed
openSound:Play()
print("Door opened. Playback speed: " .. randomPlaybackSpeed)
--------- Tween Door Close Settings ---------
local function CloseDoor()
local tweenInfo = TweenInfo.new(1.4)
local tween = game:GetService("TweenService"):Create(doorPart, tweenInfo, {Position = closedPosition})
tween:Play()
closeSound:Play()
isOpen = false
print("Door closed.")
end
isOpen = true
lastOpenTime = currentTime
canOpen = false
wait(doorStayOpenTime)
CloseDoor()
wait(cooldownTime - doorStayOpenTime)
canOpen = true
end
end
local function CheckProximity(player)
local character = player.Character
if character then
local distance = (doorPart.Position - character.HumanoidRootPart.Position).Magnitude
if distance <= proximityDistance then
OpenDoor()
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
while wait(1) do
CheckProximity(player)
end
end)
end)
- List item[quote=“MasterPixelVerse_YT, post:2, topic:2566296, full:true, username:atompest”]
local doorPart = game.Workspace:WaitForChild(“DoorPart”)
local openSound = doorPart:WaitForChild(“OpenSound”)
local closeSound = doorPart:WaitForChild(“CloseSound”)
local isOpen = false
local canOpen = true
--------- Cooldown Door Settings ---------
local cooldownTime = 10
local lastOpenTime = 0
local openPosition = doorPart.Position + Vector3.new(0, 8, 0)
local closedPosition = doorPart.Position
local doorStayOpenTime = 5
--------- Door Distance Settings ---------
local proximityDistance = 10
local function OpenDoor()
local currentTime = tick()
print(“Attempting to open the door…”)
if not isOpen and canOpen and (currentTime - lastOpenTime >= cooldownTime) then
local tweenInfo = TweenInfo.new(2.5)
--------- Tween Door Open Settings ---------
local tween = game:GetService("TweenService"):Create(doorPart, tweenInfo, {Position = openPosition})
tween:Play()
local randomPlaybackSpeed = math.random(90, 110) / 100
openSound.PlaybackSpeed = randomPlaybackSpeed
openSound:Play()
print("Door opened. Playback speed: " .. randomPlaybackSpeed)
--------- Tween Door Close Settings ---------
local function CloseDoor()
local tweenInfo = TweenInfo.new(1.4)
local tween = game:GetService("TweenService"):Create(doorPart, tweenInfo, {Position = closedPosition})
tween:Play()
closeSound:Play()
isOpen = false
print("Door closed.")
end
isOpen = true
lastOpenTime = currentTime
canOpen = false
wait(doorStayOpenTime)
CloseDoor()
wait(cooldownTime - doorStayOpenTime)
canOpen = true
end
end
local function CheckProximity(player)
local character = player.Character
if character then
local distance = (doorPart.Position - character.HumanoidRootPart.Position).Magnitude
if distance <= proximityDistance then
OpenDoor()
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
while wait(1) do
CheckProximity(player)
end
end)
end)