local RS = game:GetService("ReplicatedStorage")
local CS = game:GetService("CollectionService")
local Players = game:GetService("Players")
local PathfindingService = game:GetService("PathfindingService")
local TablesRE = RS.Packages.Knit.Services.TablesService.RE
local TablesRF = RS.Packages.Knit.Services.TablesService.RF
local LocalPlayer = Players.LocalPlayer
local NumberMap = {}
local BoardMap = {}
local FlippedBoards = {}
local AllBoardIDs = {}
local TriedBoards = {}
local CurrentTableID = nil
local NextNumber = 1
local IsSubmitting = false
local LastSubmittedBoardID = nil
local AutoLobbyEnabled = true
local IsSeated = false
local FailedSeats = {}
local function IsSeatOnCooldown(Seat)
local Expiry = FailedSeats[Seat]
if not Expiry then return false end
if tick() > Expiry then
FailedSeats[Seat] = nil
return false
end
return true
end
local function FindOpenTable()
local BestTable = nil
local BestDistance = math.huge
local HumanoidRootPart = LocalPlayer.Character and LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
if not HumanoidRootPart then return nil end
for _, T in CS:GetTagged("Table") do
local Seats = T:FindFirstChild("Seats")
if not Seats then continue end
local OccupiedCount = 0
local EmptySeat = nil
for _, S in Seats:GetChildren() do
if S:IsA("Seat") then
if S.Occupant then
OccupiedCount = OccupiedCount + 1
else
EmptySeat = S
end
end
end
if OccupiedCount == 1 and EmptySeat and not IsSeatOnCooldown(EmptySeat) then
local Dist = (EmptySeat.Position - HumanoidRootPart.Position).Magnitude
if Dist < BestDistance then
BestDistance = Dist
BestTable = EmptySeat
end
end
end
if not BestTable then
for _, T in CS:GetTagged("Table") do
local Seats = T:FindFirstChild("Seats")
if not Seats then continue end
local OccupiedCount = 0
local EmptySeat = nil
for _, S in Seats:GetChildren() do
if S:IsA("Seat") then
if S.Occupant then
OccupiedCount = OccupiedCount + 1
else
EmptySeat = S
end
end
end
if OccupiedCount == 0 and EmptySeat and not IsSeatOnCooldown(EmptySeat) then
local Dist = (EmptySeat.Position - HumanoidRootPart.Position).Magnitude
if Dist < BestDistance then
BestDistance = Dist
BestTable = EmptySeat
end
end
end
end
return BestTable
end
local function IsSeatStillValid(Seat)
if not Seat or not Seat.Parent then return false end
if Seat.Occupant then return false end
local PP = Seat:FindFirstChildOfClass("ProximityPrompt")
if PP and not PP.Enabled then return false end
return true
end
local function WalkToSeat(Seat)
local Character = LocalPlayer.Character
if not Character then return false end
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
if not Humanoid or not HumanoidRootPart then return false end
if not IsSeatStillValid(Seat) then return false end
local Path = PathfindingService:CreatePath({
AgentRadius = 2,
AgentHeight = 5,
AgentCanJump = true,
AgentCanClimb = false,
})
local Success, Err = nil, nil
Success, Err = xpcall(function()
Path:ComputeAsync(HumanoidRootPart.Position, Seat.Position)
end, function(E) return E end)
if not Success then return false end
if Path.Status ~= Enum.PathStatus.Success then return false end
local Waypoints = Path:GetWaypoints()
for _, Waypoint in Waypoints do
if not AutoLobbyEnabled or IsSeated then return false end
if not IsSeatStillValid(Seat) then
Humanoid:MoveTo(HumanoidRootPart.Position)
return false
end
Humanoid:MoveTo(Waypoint.Position)
if Waypoint.Action == Enum.PathWaypointAction.Jump then
Humanoid.Jump = true
end
local Reached = Humanoid.MoveToFinished:Wait()
if not Reached then return false end
end
if not IsSeatStillValid(Seat) then return false end
return true
end
local function FireProximityPrompt(Seat)
local PP = Seat:FindFirstChildOfClass("ProximityPrompt")
if not PP then return false end
if not PP.Enabled then return false end
PP.HoldDuration = 0
if fireproximityprompt then
fireproximityprompt(PP)
else
PP:InputHoldBegin()
task.wait(0.1)
PP:InputHoldEnd()
end
return true
end
local function AutoLobbyLoop()
while AutoLobbyEnabled do
if not IsSeated then
local Seat = FindOpenTable()
if Seat then
local Arrived = WalkToSeat(Seat)
if Arrived and not IsSeated and IsSeatStillValid(Seat) then
task.wait(0.3)
if IsSeatStillValid(Seat) then
FireProximityPrompt(Seat)
local Seated = false
for I = 1, 10 do
task.wait(0.3)
if IsSeated then
Seated = true
break
end
end
if not Seated then
local Character = LocalPlayer.Character
local Humanoid = Character and Character:FindFirstChildOfClass("Humanoid")
if Humanoid and IsSeatStillValid(Seat) then
Humanoid:MoveTo(Seat.Position)
Humanoid.MoveToFinished:Wait()
task.wait(0.3)
if IsSeatStillValid(Seat) then
FireProximityPrompt(Seat)
end
for I = 1, 6 do
task.wait(0.3)
if IsSeated then
Seated = true
break
end
end
end
if not Seated then
FailedSeats[Seat] = tick() + 15
end
end
end
else
FailedSeats[Seat] = tick() + 10
end
end
end
task.wait(0.5)
end
end
local function GetAllBoardIDs()
AllBoardIDs = {}
for _, T in CS:GetTagged("Table") do
if T:GetAttribute("ID") == CurrentTableID then
local Boards = T:FindFirstChild("Boards")
if Boards then
for _, B in Boards:GetChildren() do
if B:IsA("Model") then
local BID = B:GetAttribute("ID")
if BID then
table.insert(AllBoardIDs, BID)
end
end
end
end
break
end
end
end
local function GetUnknownBoard()
for _, BID in AllBoardIDs do
if not BoardMap[BID] and not FlippedBoards[BID] and not TriedBoards[BID] then
return BID
end
end
return nil
end
local function ResetState()
IsSeated = false
CurrentTableID = nil
NumberMap = {}
BoardMap = {}
FlippedBoards = {}
AllBoardIDs = {}
TriedBoards = {}
FailedSeats = {}
NextNumber = 1
IsSubmitting = false
end
TablesRE.OnBoardFlip.OnClientEvent:Connect(function(Data)
if not Data or not Data.Model or not Data.Number then return end
local BID = Data.Model:GetAttribute("ID")
if not BID then return end
NumberMap[Data.Number] = BID
BoardMap[BID] = Data.Number
end)
TablesRE.OnBoardsReset.OnClientEvent:Connect(function()
NextNumber = 1
FlippedBoards = {}
TriedBoards = {}
IsSubmitting = false
end)
TablesRE.OnPickedBoard.OnClientEvent:Connect(function(Correct)
IsSubmitting = false
if Correct then
local BID = NumberMap[NextNumber]
if not BID and LastSubmittedBoardID then
BID = LastSubmittedBoardID
NumberMap[NextNumber] = BID
BoardMap[BID] = NextNumber
end
if BID then
FlippedBoards[BID] = true
end
NextNumber = NextNumber + 1
end
end)
TablesRE.OnPickTurn.OnClientEvent:Connect(function(TableID)
if TableID and type(TableID) == "string" then
CurrentTableID = TableID
end
if not CurrentTableID then return end
if IsSubmitting then return end
if #AllBoardIDs == 0 then
GetAllBoardIDs()
end
task.wait(0.2)
local BoardID = NumberMap[NextNumber]
if not BoardID then
BoardID = GetUnknownBoard()
end
if not BoardID then
TriedBoards = {}
BoardID = GetUnknownBoard()
end
if BoardID then
IsSubmitting = true
LastSubmittedBoardID = BoardID
TriedBoards[BoardID] = true
task.spawn(function()
TablesRF.OnPicked:InvokeServer(CurrentTableID, BoardID)
end)
end
end)
TablesRE.OnPickStopped.OnClientEvent:Connect(function()
IsSubmitting = false
end)
TablesRE.OnPlayerSeated.OnClientEvent:Connect(function()
IsSeated = true
end)
TablesRE.OnMatchEnded.OnClientEvent:Connect(function()
IsSubmitting = false
task.wait(3)
ResetState()
end)
TablesRE.OnLose.OnClientEvent:Connect(function()
IsSubmitting = false
task.wait(3)
ResetState()
end)
TablesRE.OnVictory.OnClientEvent:Connect(function()
IsSubmitting = false
task.wait(3)
ResetState()
end)
TablesRE.OnPlayerUnSeated.OnClientEvent:Connect(function()
ResetState()
end)
LocalPlayer.CharacterAdded:Connect(function(Character)
ResetState()
Character:WaitForChild("HumanoidRootPart")
Character:WaitForChild("Humanoid")
task.wait(1)
end)
task.spawn(AutoLobbyLoop)Enhance your gameplay in Number Memory with this intelligent Auto Play & Auto Lobby system. The script automatically finds open tables, seats your character, memorizes board numbers, and selects the correct order during your turn. Built with smart tracking and fail-safe resets, it keeps gameplay smooth and efficient.
No comments yet. Be the first to comment!
1local RS = game:GetService("ReplicatedStorage")
2local CS = game:GetService("CollectionService")
3local Players = game:GetService("Players")
4local PathfindingService = game:GetService("PathfindingService")
5local TablesRE = RS.Packages.Knit.Services.TablesService.RE
6local TablesRF = RS.Packages.Knit.Services.TablesService.RF
7local LocalPlayer = Players.LocalPlayer
8
9local NumberMap = {}
10local BoardMap = {}
11local FlippedBoards = {}
12local AllBoardIDs = {}
13local TriedBoards = {}
14local CurrentTableID = nil
15local NextNumber = 1
16local IsSubmitting = false
17local LastSubmittedBoardID = nil
18local AutoLobbyEnabled = true
19local IsSeated = false
20local FailedSeats = {}
21
22local function IsSeatOnCooldown(Seat)
23 local Expiry = FailedSeats[Seat]
24 if not Expiry then return false end
25 if tick() > Expiry then
26 FailedSeats[Seat] = nil
27 return false
28 end
29 return true
30end
31
32local function FindOpenTable()
33 local BestTable = nil
34 local BestDistance = math.huge
35 local HumanoidRootPart = LocalPlayer.Character and LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
36 if not HumanoidRootPart then return nil end
37 for _, T in CS:GetTagged("Table") do
38 local Seats = T:FindFirstChild("Seats")
39 if not Seats then continue end
40 local OccupiedCount = 0
41 local EmptySeat = nil
42 for _, S in Seats:GetChildren() do
43 if S:IsA("Seat") then
44 if S.Occupant then
45 OccupiedCount = OccupiedCount + 1
46 else
47 EmptySeat = S
48 end
49 end
50 end
51 if OccupiedCount == 1 and EmptySeat and not IsSeatOnCooldown(EmptySeat) then
52 local Dist = (EmptySeat.Position - HumanoidRootPart.Position).Magnitude
53 if Dist < BestDistance then
54 BestDistance = Dist
55 BestTable = EmptySeat
56 end
57 end
58 end
59 if not BestTable then
60 for _, T in CS:GetTagged("Table") do
61 local Seats = T:FindFirstChild("Seats")
62 if not Seats then continue end
63 local OccupiedCount = 0
64 local EmptySeat = nil
65 for _, S in Seats:GetChildren() do
66 if S:IsA("Seat") then
67 if S.Occupant then
68 OccupiedCount = OccupiedCount + 1
69 else
70 EmptySeat = S
71 end
72 end
73 end
74 if OccupiedCount == 0 and EmptySeat and not IsSeatOnCooldown(EmptySeat) then
75 local Dist = (EmptySeat.Position - HumanoidRootPart.Position).Magnitude
76 if Dist < BestDistance then
77 BestDistance = Dist
78 BestTable = EmptySeat
79 end
80 end
81 end
82 end
83 return BestTable
84end
85
86local function IsSeatStillValid(Seat)
87 if not Seat or not Seat.Parent then return false end
88 if Seat.Occupant then return false end
89 local PP = Seat:FindFirstChildOfClass("ProximityPrompt")
90 if PP and not PP.Enabled then return false end
91 return true
92end
93
94local function WalkToSeat(Seat)
95 local Character = LocalPlayer.Character
96 if not Character then return false end
97 local Humanoid = Character:FindFirstChildOfClass("Humanoid")
98 local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
99 if not Humanoid or not HumanoidRootPart then return false end
100 if not IsSeatStillValid(Seat) then return false end
101 local Path = PathfindingService:CreatePath({
102 AgentRadius = 2,
103 AgentHeight = 5,
104 AgentCanJump = true,
105 AgentCanClimb = false,
106 })
107 local Success, Err = nil, nil
108 Success, Err = xpcall(function()
109 Path:ComputeAsync(HumanoidRootPart.Position, Seat.Position)
110 end, function(E) return E end)
111 if not Success then return false end
112 if Path.Status ~= Enum.PathStatus.Success then return false end
113 local Waypoints = Path:GetWaypoints()
114 for _, Waypoint in Waypoints do
115 if not AutoLobbyEnabled or IsSeated then return false end
116 if not IsSeatStillValid(Seat) then
117 Humanoid:MoveTo(HumanoidRootPart.Position)
118 return false
119 end
120 Humanoid:MoveTo(Waypoint.Position)
121 if Waypoint.Action == Enum.PathWaypointAction.Jump then
122 Humanoid.Jump = true
123 end
124 local Reached = Humanoid.MoveToFinished:Wait()
125 if not Reached then return false end
126 end
127 if not IsSeatStillValid(Seat) then return false end
128 return true
129end
130
131local function FireProximityPrompt(Seat)
132 local PP = Seat:FindFirstChildOfClass("ProximityPrompt")
133 if not PP then return false end
134 if not PP.Enabled then return false end
135 PP.HoldDuration = 0
136 if fireproximityprompt then
137 fireproximityprompt(PP)
138 else
139 PP:InputHoldBegin()
140 task.wait(0.1)
141 PP:InputHoldEnd()
142 end
143 return true
144end
145
146local function AutoLobbyLoop()
147 while AutoLobbyEnabled do
148 if not IsSeated then
149 local Seat = FindOpenTable()
150 if Seat then
151 local Arrived = WalkToSeat(Seat)
152 if Arrived and not IsSeated and IsSeatStillValid(Seat) then
153 task.wait(0.3)
154 if IsSeatStillValid(Seat) then
155 FireProximityPrompt(Seat)
156 local Seated = false
157 for I = 1, 10 do
158 task.wait(0.3)
159 if IsSeated then
160 Seated = true
161 break
162 end
163 end
164 if not Seated then
165 local Character = LocalPlayer.Character
166 local Humanoid = Character and Character:FindFirstChildOfClass("Humanoid")
167 if Humanoid and IsSeatStillValid(Seat) then
168 Humanoid:MoveTo(Seat.Position)
169 Humanoid.MoveToFinished:Wait()
170 task.wait(0.3)
171 if IsSeatStillValid(Seat) then
172 FireProximityPrompt(Seat)
173 end
174 for I = 1, 6 do
175 task.wait(0.3)
176 if IsSeated then
177 Seated = true
178 break
179 end
180 end
181 end
182 if not Seated then
183 FailedSeats[Seat] = tick() + 15
184 end
185 end
186 end
187 else
188 FailedSeats[Seat] = tick() + 10
189 end
190 end
191 end
192 task.wait(0.5)
193 end
194end
195
196local function GetAllBoardIDs()
197 AllBoardIDs = {}
198 for _, T in CS:GetTagged("Table") do
199 if T:GetAttribute("ID") == CurrentTableID then
200 local Boards = T:FindFirstChild("Boards")
201 if Boards then
202 for _, B in Boards:GetChildren() do
203 if B:IsA("Model") then
204 local BID = B:GetAttribute("ID")
205 if BID then
206 table.insert(AllBoardIDs, BID)
207 end
208 end
209 end
210 end
211 break
212 end
213 end
214end
215
216local function GetUnknownBoard()
217 for _, BID in AllBoardIDs do
218 if not BoardMap[BID] and not FlippedBoards[BID] and not TriedBoards[BID] then
219 return BID
220 end
221 end
222 return nil
223end
224
225local function ResetState()
226 IsSeated = false
227 CurrentTableID = nil
228 NumberMap = {}
229 BoardMap = {}
230 FlippedBoards = {}
231 AllBoardIDs = {}
232 TriedBoards = {}
233 FailedSeats = {}
234 NextNumber = 1
235 IsSubmitting = false
236end
237
238TablesRE.OnBoardFlip.OnClientEvent:Connect(function(Data)
239 if not Data or not Data.Model or not Data.Number then return end
240 local BID = Data.Model:GetAttribute("ID")
241 if not BID then return end
242 NumberMap[Data.Number] = BID
243 BoardMap[BID] = Data.Number
244end)
245
246TablesRE.OnBoardsReset.OnClientEvent:Connect(function()
247 NextNumber = 1
248 FlippedBoards = {}
249 TriedBoards = {}
250 IsSubmitting = false
251end)
252
253TablesRE.OnPickedBoard.OnClientEvent:Connect(function(Correct)
254 IsSubmitting = false
255 if Correct then
256 local BID = NumberMap[NextNumber]
257 if not BID and LastSubmittedBoardID then
258 BID = LastSubmittedBoardID
259 NumberMap[NextNumber] = BID
260 BoardMap[BID] = NextNumber
261 end
262 if BID then
263 FlippedBoards[BID] = true
264 end
265 NextNumber = NextNumber + 1
266 end
267end)
268
269TablesRE.OnPickTurn.OnClientEvent:Connect(function(TableID)
270 if TableID and type(TableID) == "string" then
271 CurrentTableID = TableID
272 end
273 if not CurrentTableID then return end
274 if IsSubmitting then return end
275 if #AllBoardIDs == 0 then
276 GetAllBoardIDs()
277 end
278 task.wait(0.2)
279 local BoardID = NumberMap[NextNumber]
280 if not BoardID then
281 BoardID = GetUnknownBoard()
282 end
283 if not BoardID then
284 TriedBoards = {}
285 BoardID = GetUnknownBoard()
286 end
287 if BoardID then
288 IsSubmitting = true
289 LastSubmittedBoardID = BoardID
290 TriedBoards[BoardID] = true
291 task.spawn(function()
292 TablesRF.OnPicked:InvokeServer(CurrentTableID, BoardID)
293 end)
294 end
295end)
296
297TablesRE.OnPickStopped.OnClientEvent:Connect(function()
298 IsSubmitting = false
299end)
300
301TablesRE.OnPlayerSeated.OnClientEvent:Connect(function()
302 IsSeated = true
303end)
304
305TablesRE.OnMatchEnded.OnClientEvent:Connect(function()
306 IsSubmitting = false
307 task.wait(3)
308 ResetState()
309end)
310
311TablesRE.OnLose.OnClientEvent:Connect(function()
312 IsSubmitting = false
313 task.wait(3)
314 ResetState()
315end)
316
317TablesRE.OnVictory.OnClientEvent:Connect(function()
318 IsSubmitting = false
319 task.wait(3)
320 ResetState()
321end)
322
323TablesRE.OnPlayerUnSeated.OnClientEvent:Connect(function()
324 ResetState()
325end)
326
327LocalPlayer.CharacterAdded:Connect(function(Character)
328 ResetState()
329 Character:WaitForChild("HumanoidRootPart")
330 Character:WaitForChild("Humanoid")
331 task.wait(1)
332end)
333
334task.spawn(AutoLobbyLoop)