-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatchmaking.lua
More file actions
372 lines (349 loc) · 13.1 KB
/
Copy pathMatchmaking.lua
File metadata and controls
372 lines (349 loc) · 13.1 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
local TPS = game:GetService("TeleportService")
local checkValid = require(game.ReplicatedStorage.CheckValidPlayer)
local getData = require(game.ReplicatedStorage.GetData)
local TouchParts = {}
local stuff = workspace:GetDescendants()
for i = 1, #stuff do
if stuff[i].Name == "QueueTouch" then
table.insert(TouchParts,stuff[i])
end
end
local queueMap = {}
local queueMapCounters = {}
local queueIsTeleporting = {}
for i = 1, #TouchParts do
local nightName = TouchParts[i].Parent.NightName.Value
queueMap[nightName] = {"EMPTY","EMPTY","EMPTY","EMPTY"}
queueMapCounters[nightName] = 0
queueIsTeleporting[nightName] = false
end
function getSeatIndex(nightName)
local queue = queueMap[nightName]
for i = 1, #queue do
if queue[i] == "EMPTY" then
return i
end
end
return nil
end
function getPlayerIndex(nightName,player)
local queue = queueMap[nightName]
for i = 1, #queue do
if queue[i] == player then
return i
end
end
return nil
end
script.StartTimer.Event:Connect(function(timerVal,nightName)
timerVal.Value = 25
repeat
wait(1)
if timerVal.Value ~= 999 then
timerVal.Value = timerVal.Value - 1
end
until timerVal.Value <= 0 or timerVal.Value == 999
if timerVal.Value <= 0 and queueIsTeleporting[nightName] == false then
queueIsTeleporting[nightName] = true
for i = 1, #queueMap[nightName] do
local player = queueMap[nightName][i]
if type(player) ~= "string" and player ~= nil then
local playerData = getData.getDataFromPlayer(player)
if playerData then
playerData.Queue.Value = "TP"
end
game.ReplicatedStorage.Remotes.ChangeUI:FireClient(player,"Hide")
game.ReplicatedStorage.Remotes.Fade:FireClient(player,Color3.fromRGB(18, 0, 36),1,.5,1)
game.ReplicatedStorage.Remotes.PlaySound:FireClient(player,"FadeOut","MainThemeLoop")
end
end
wait(1.25)
local playersToTP = {}
for i = 1, #queueMap[nightName] do
local player = queueMap[nightName][i]
if type(player) ~= "string" and player ~= nil and checkValid.checkPlayer(player) then
table.insert(playersToTP,player)
player.Character.HumanoidRootPart.CFrame = workspace.TPSPOT.CFrame
end
end
local difficultyData = nil
if nightName == "Custom" and game.ReplicatedStorage.IsVip.Value == true then
difficultyData = {}
difficultyData["RedBelly"] = workspace.CustomSettings.RedBellySetting.DifficultySetting.Value
difficultyData["Kitty"] = workspace.CustomSettings.KittySetting.DifficultySetting.Value
difficultyData["Honey"] = workspace.CustomSettings.HoneySetting.DifficultySetting.Value
difficultyData["Starry"] = workspace.CustomSettings.StarrySetting.DifficultySetting.Value
difficultyData["Wailey"] = workspace.CustomSettings.WaileySetting.DifficultySetting.Value
difficultyData["Froggy"] = workspace.CustomSettings.FroggySetting.DifficultySetting.Value
end
local QueueData = {
NightName = nightName,
Difficulties = difficultyData
}
script.TeleportPlayers:Fire(playersToTP,QueueData)
queueIsTeleporting[nightName] = false
queueMap[nightName] = {"EMPTY","EMPTY","EMPTY","EMPTY"}
updateCounter(nightName)
end
end)
function updateCounter(nightName)
local maxCount = 4
local count = 0
local queue = queueMap[nightName]
for i = 1, #queue do
if queue[i] ~= "EMPTY" then
count = count + 1
end
end
workspace[nightName].BillBoardPart.BillboardGui.Frame.Counter.Text = count.."/"..maxCount
if count == 0 then
workspace[nightName].TimerVal.Value = 999
end
if count ~= 0 and workspace[nightName].TimerVal.Value == 999 then
script.StartTimer:Fire(workspace[nightName].TimerVal,nightName)
end
end
function removePlayer(player)
local playerData = getData.getDataFromPlayer(player)
if playerData and playerData.Queue.Value ~= "" and playerData.Queue.Value ~= nil and playerData.Queue.Value ~= "TP" then
local queueName = playerData.Queue.Value
if queueIsTeleporting[queueName] == false then
local nightQueue = queueMap[queueName]
playerData.Queue.Value = ""
local index = getPlayerIndex(queueName,player)
if index then
nightQueue[index] = "EMPTY"
end
if checkValid.checkPlayer(player) then
player.Character.HumanoidRootPart.CFrame = workspace[queueName].ExitSpot.CFrame
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(player,"Stop","QueuePoseLie")
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(player,"Stop","QueuePoseSit")
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(player,"Stop","QueuePoseUpSideDown")
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(player,"Stop","QueuePoseClap")
if player.Character:FindFirstChild("HB") then
player.Character.HB.CanTouch = true
end
if index == 2 and nightQueue[3] ~= "EMPTY" then
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(nightQueue[3],"Stop","QueuePoseClap")
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(nightQueue[3],"Play","QueuePoseSit")
end
if index == 3 and nightQueue[2] ~= "EMPTY" then
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(nightQueue[2],"Stop","QueuePoseClap")
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(nightQueue[2],"Play","QueuePoseSit")
end
updateCounter(queueName)
wait(.1)
if checkValid.checkPlayer(player) then
local weld = player.Character.HumanoidRootPart:FindFirstChild("BedWeld")
if weld then
weld.Part1:Destroy()
weld:Destroy()
end
end
end
updateCounter(queueName)
end
end
end
game.ReplicatedStorage.Remotes.LeaveQueue.OnServerEvent:Connect(function(player)
removePlayer(player)
end)
game.Players.PlayerRemoving:Connect(function(player)
removePlayer(player)
end)
script.RemovePlayer.Event:Connect(function(player)
removePlayer(player)
end)
script.TeleportPlayers.Event:Connect(function(playersToTP,QueueData)
for i = 1, #playersToTP do
if playersToTP[i] == nil then
table.remove(playersToTP,i)
end
end
if #playersToTP < 1 then
return
end
local code = nil
local success, errorMessage = pcall(function()
code = TPS:ReserveServer(13656644128)
end)
if not success then
print("RESERVE ERROR "..errorMessage)
end
if code then
--[[for i = 1, #playersToTP do
local teleportData = {
Night = QueueData["NightName"],
Difficulties = QueueData["Difficulties"]
}
local success, errorMessage = pcall(function()
TPS:TeleportToPrivateServer(13656644128,code,{playersToTP[i]},nil,teleportData)
end)
end]]
local teleportData = {
Night = QueueData["NightName"],
Difficulties = QueueData["Difficulties"]
}
local success, errorMessage = pcall(function()
TPS:TeleportToPrivateServer(13656644128,code,playersToTP,nil,teleportData)
end)
end
wait(10)
local playersLeft = {}
for i = 1, #playersToTP do
if playersToTP[i] and game.Players:FindFirstChild(playersToTP[i].Name) then
table.insert(playersLeft,playersToTP[i])
end
end
wait(10)
for i = 1, #playersLeft do
if playersLeft[i] and game.Players:FindFirstChild(playersLeft[i].Name) then
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(playersLeft[i],"Stop","QueuePoseLie")
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(playersLeft[i],"Stop","QueuePoseSit")
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(playersLeft[i],"Stop","QueuePoseUpSideDown")
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(playersLeft[i],"Stop","QueuePoseClap")
if playersLeft[i] and playersLeft[i].Character and playersLeft[i].Character:FindFirstChild("HumanoidRootPart") then
playersLeft[i].Character.HumanoidRootPart.CFrame = workspace.SpawnSpot.CFrame
end
game.ReplicatedStorage.Remotes.PlaySound:FireClient(playersLeft[i],"FadeIn","MainThemeLoop")
wait(.1)
if checkValid.checkPlayer(playersLeft[i]) then
local weld = playersLeft[i].Character.HumanoidRootPart:FindFirstChild("BedWeld")
if weld then
weld.Part1:Destroy()
weld:Destroy()
end
playersLeft[i].Character.HB.CanTouch = true
end
if getData.getDataFromPlayer(playersLeft[i]) then
local playerData = getData.getDataFromPlayer(playersLeft[i])
playerData.Queue.Value = ""
end
end
end
end)
script.AddPlayer.Event:Connect(function(player,touchPart)
local nightName = touchPart.Parent.NightName.Value
if getSeatIndex(nightName) ~= nil and checkValid.checkPlayer(player) then
local seatIndex = getSeatIndex(nightName)
local nightNum = touchPart.Parent.NightNum.Value
local playerData = getData.getDataFromPlayer(player)
if playerData and playerData.NightUnlocked.Value >= nightNum and (playerData.Queue.Value == "" or playerData.Queue.Value == nil) then
queueMap[nightName][seatIndex] = player
playerData.Queue.Value = nightName
updateCounter(nightName)
local weld = Instance.new("Weld")
weld.Part0 = player.Character.HumanoidRootPart
local partclone = touchPart.Parent["AnimSpot"..seatIndex]:Clone()
partclone.Parent = workspace
weld.Part1 = partclone
weld.Parent = player.Character.HumanoidRootPart
weld.C0 = CFrame.new(0,0,0)
weld.C1 = CFrame.new(0,0,0)
weld.Name = "BedWeld"
if seatIndex == 1 then
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(player,"Play","QueuePoseLie")
end
if seatIndex == 2 then
if queueMap[nightName][3] == "EMPTY" then
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(player,"Play","QueuePoseSit")
else
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(player,"Play","QueuePoseClap")
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(queueMap[nightName][3],"Stop","QueuePoseSit")
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(queueMap[nightName][3],"Play","QueuePoseClap")
end
end
if seatIndex == 3 then
if queueMap[nightName][2] == "EMPTY" then
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(player,"Play","QueuePoseSit")
else
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(player,"Play","QueuePoseClap")
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(queueMap[nightName][2],"Stop","QueuePoseSit")
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(queueMap[nightName][2],"Play","QueuePoseClap")
end
end
if seatIndex == 4 then
game.ReplicatedStorage.Remotes.PlayAnim:FireClient(player,"Play","QueuePoseUpSideDown")
end
if player.Character:FindFirstChild("HB") then
player.Character.HB.CanTouch = false
end
local seatNumStart = nil
local players = game.Players:GetChildren()
if #players == 1 then
seatNumStart = 2
end
if #players == 2 then
seatNumStart = 3
end
if #players == 3 then
seatNumStart = 4
end
--seatNumStart = nil
if getSeatIndex(nightName) == seatNumStart then
queueMapCounters[nightName] = queueMapCounters[nightName] + 1
local myQueueCount = queueMapCounters[nightName]
wait(2.25)
if getSeatIndex(nightName) == seatNumStart and myQueueCount == queueMapCounters[nightName] and queueIsTeleporting[nightName] == false then
queueIsTeleporting[nightName] = true
for i = 1, #queueMap[nightName] do
local player = queueMap[nightName][i]
if type(player) ~= "string" and player ~= nil then
local playerData = getData.getDataFromPlayer(player)
if playerData then
playerData.Queue.Value = "TP"
end
game.ReplicatedStorage.Remotes.ChangeUI:FireClient(player,"Hide")
game.ReplicatedStorage.Remotes.Fade:FireClient(player,Color3.fromRGB(18, 0, 36),1,.5,1)
game.ReplicatedStorage.Remotes.PlaySound:FireClient(player,"FadeOut","MainThemeLoop")
end
end
wait(1.25)
local playersToTP = {}
for i = 1, #queueMap[nightName] do
local player = queueMap[nightName][i]
if type(player) ~= "string" and player ~= nil and checkValid.checkPlayer(player) then
table.insert(playersToTP,player)
player.Character.HumanoidRootPart.CFrame = workspace.TPSPOT.CFrame
end
end
local difficultyData = nil
if nightName == "Custom" and game.ReplicatedStorage.IsVip.Value == true then
difficultyData = {}
difficultyData["RedBelly"] = workspace.CustomSettings.RedBellySetting.DifficultySetting.Value
difficultyData["Kitty"] = workspace.CustomSettings.KittySetting.DifficultySetting.Value
difficultyData["Honey"] = workspace.CustomSettings.HoneySetting.DifficultySetting.Value
difficultyData["Starry"] = workspace.CustomSettings.StarrySetting.DifficultySetting.Value
difficultyData["Wailey"] = workspace.CustomSettings.WaileySetting.DifficultySetting.Value
difficultyData["Froggy"] = workspace.CustomSettings.FroggySetting.DifficultySetting.Value
end
local QueueData = {
NightName = nightName,
Difficulties = difficultyData
}
script.TeleportPlayers:Fire(playersToTP,QueueData)
queueIsTeleporting[nightName] = false
queueMap[nightName] = {"EMPTY","EMPTY","EMPTY","EMPTY"}
updateCounter(nightName)
end
end
end
end
end)
for i = 1, #TouchParts do
TouchParts[i].TouchedEvent.Event:Connect(function(player)
script.AddPlayer:Fire(player,TouchParts[i])
end)
end
while true do
wait(1)
for i = 1, #TouchParts do
local touchingParts = TouchParts[i]:GetTouchingParts()
for j = 1, #touchingParts do
local player = game.Players:GetPlayerFromCharacter(touchingParts[j].Parent)
if player then
script.AddPlayer:Fire(player,TouchParts[i])
end
end
end
end