-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDoorTimerScript
116 lines (80 loc) · 2.23 KB
/
DoorTimerScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local doors = {}
for _, obj in ipairs(workspace:GetChildren()) do
if obj:IsA("Model") and obj:FindFirstChild("MainFrame") and obj:FindFirstChild("Hinge") then
table.insert(doors, {
model = obj,
hinge = obj:FindFirstChild("Hinge"),
originalCFrame = obj:FindFirstChild("Hinge").CFrame
})
end
end
local timerPart = workspace:FindFirstChild("TimerDisplayPart")
local timerLabel = timerPart:FindFirstChild("SurfaceGui"):FindFirstChild("TimerLabel")
local unlockTime = 5
local openDuration = 5
local platform = workspace:FindFirstChild("TimerPlatform")
local playersTouchedPlatform = {}
local function updateDoor(doorData, status)
local hinge = doorData.hinge
if hinge then
local goal = {}
if status == "open" then
goal.CFrame = doorData.originalCFrame * CFrame.Angles(0, math.rad(270), 0)
else
goal.CFrame = doorData.originalCFrame
end
local tweenInfo = TweenInfo.new(1)
local tween = TweenService:Create(hinge, tweenInfo, goal)
tween:Play()
end
end
local function onPlatformTouch(otherPart)
local player = Players:GetPlayerFromCharacter(otherPart.Parent)
if player then
playersTouchedPlatform[player] = true
end
end
if platform then
platform.Touched:Connect(onPlatformTouch)
end
while true do
for i = unlockTime, 0, -1 do
timerLabel.Text = "Doors open in: " .. i .. "s"
wait(1)
end
for _, doorData in ipairs(doors) do
updateDoor(doorData, "open")
end
for i = openDuration, 0, -1 do
timerLabel.Text = "Doors closing in: " .. i .. "s"
wait(1)
end
for _, doorData in ipairs(doors) do
updateDoor(doorData, "closed")
end
for _, player in ipairs(Players:GetPlayers()) do
if not playersTouchedPlatform[player] then
local character = player.Character
if character then
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
end
end
for i = unlockTime, 0, -1 do
timerLabel.Text = "Doors open in: " .. i .. "s"
wait(1)
end
for _, doorData in ipairs(doors) do
updateDoor(doorData, "open")
end
playersTouchedPlatform = {}
wait(5)
for _, doorData in ipairs(doors) do
updateDoor(doorData, "closed")
end
end