Apokalive

Work at a pizza place script

Mar 28th, 2025
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.98 KB | None | 0 0
  1. -- local EventHandler = filtergc("function", {Name = "GetEventHandler"}, true)
  2. -- no filtergc LOL!
  3. local EventHandler
  4.  
  5. for i,v in pairs(getgc()) do
  6. if typeof(v) == "function" and islclosure(v) and not is_synapse_function(v) and debug.getinfo(v).name == "GetEventHandler" then
  7. print('found')
  8. EventHandler = v
  9. end
  10. end
  11.  
  12. local Table2 = getupvalue(EventHandler, 1)
  13.  
  14. for i,v in pairs(Table2) do
  15. if v.Remote then
  16. v.Remote.Name = i
  17. end
  18. end
  19.  
  20. local LocalPlayer = game.Players.LocalPlayer
  21. local Events = game:GetService("ReplicatedStorage"):WaitForChild("Communication"):WaitForChild("Events")
  22.  
  23. local function FindChildByIndexSequence(Parent, IndexSequence)
  24. local CurrentChild = Parent
  25. for _, Index in ipairs(IndexSequence) do
  26. CurrentChild = CurrentChild:FindFirstChild(tostring(Index))
  27. if not CurrentChild then
  28. return nil
  29. end
  30. end
  31. return CurrentChild
  32. end
  33.  
  34. local function WalkToPoint(TargetPoint)
  35. local Humanoid = LocalPlayer.Character:FindFirstChild("Humanoid")
  36. if Humanoid then
  37. Humanoid:MoveTo(TargetPoint)
  38. end
  39.  
  40. return function()
  41. repeat wait() Humanoid:MoveTo(TargetPoint) until (LocalPlayer.Character.HumanoidRootPart.Position * Vector3.new(1,0,1) - TargetPoint * Vector3.new(1,0,1)).Magnitude < 2
  42. end
  43. end
  44.  
  45. local function TeleportToJob(Name)
  46. local args = {
  47. [1] = "TeleportToJob",
  48. [2] = Name
  49. }
  50.  
  51. game:GetService("ReplicatedStorage"):WaitForChild("PlayerChannel"):FireServer(unpack(args))
  52. end
  53.  
  54. for i,v in pairs(getconnections(workspace.Main.GivePaycheck.OnClientEvent)) do
  55. v:Disable()
  56. end
  57.  
  58. local function ClaimPaycheck()
  59. workspace:WaitForChild("Main"):WaitForChild("GivePaycheck"):FireServer("Paycheck", false)
  60. end
  61.  
  62. local MainClass = {}
  63.  
  64. MainClass.CharacterAddedConnections = {}
  65.  
  66. function MainClass:Init(HideOtherCharacters)
  67. if HideOtherCharacters then
  68. for _, Player in next, game.Players:GetPlayers() do
  69. if Player ~= LocalPlayer then
  70. Player.Character.Parent = nil
  71. local CharacterConnection
  72. CharacterConnection = Player.CharacterAdded:Connect(function(Character)
  73. wait(0.1)
  74. Character.Parent = nil
  75. end)
  76. self.CharacterAddedConnections[Player] = CharacterConnection
  77. end
  78. end
  79. game.Players.PlayerAdded:Connect(function(Player)
  80. if Player ~= LocalPlayer then
  81. local CharacterConnection
  82. CharacterConnection = Player.CharacterAdded:Connect(function(Character)
  83. wait(0.1)
  84. Character.Parent = nil
  85. end)
  86. self.CharacterAddedConnections[Player] = CharacterConnection
  87. end
  88. end)
  89. game.Players.PlayerRemoving:Connect(function(Player)
  90. local Connection = self.CharacterAddedConnections[Player]
  91. if Connection then
  92. Connection:Disconnect()
  93. self.CharacterAddedConnections[Player] = nil
  94. end
  95. end)
  96. workspace.Main.GivePaycheck.OnClientEvent:Connect(ClaimPaycheck)
  97. end
  98. end
  99.  
  100. local CashierClass = {}
  101.  
  102. CashierClass.Timeout = 10
  103. CashierClass.Registers = {workspace.Register1, workspace.Register2, workspace.Register3}
  104.  
  105. function CashierClass:GetCustomers()
  106. local ValidCustomers = {}
  107.  
  108. for _,Customer in next, workspace.Customers:GetChildren() do
  109. local InUse = FindChildByIndexSequence(Customer, {"Head", "InUse"})
  110. if InUse and InUse.Value == false and Customer:FindFirstChild("Torso") and (Customer.Torso.Velocity.Magnitude < 1 or math.round(Customer.Torso.Velocity.Z) == -15) and (Customer.HumanoidRootPart.Position - self:GetRegisterFromCustomer(Customer).Screen.Position).Magnitude < 22 and not Customer:GetAttribute("AlreadyHandled") then
  111. table.insert(ValidCustomers, Customer)
  112. end
  113. end
  114.  
  115. return ValidCustomers
  116. end
  117.  
  118. function CashierClass:GetRegisterFromCustomer(Customer)
  119. local BestRegister, BestDistance = nil, math.huge
  120. for _, Register in next, self.Registers do
  121. if Customer:FindFirstChild("HumanoidRootPart") and (Customer.HumanoidRootPart.Position - Register.Screen.Position).Magnitude < BestDistance then
  122. BestDistance = (Customer.HumanoidRootPart.Position - Register.Screen.Position).Magnitude
  123. BestRegister = Register
  124. end
  125. end
  126.  
  127. return BestRegister
  128. end
  129.  
  130. function CashierClass:GetClosestValidCustomer()
  131. local Customers = CashierClass:GetCustomers()
  132.  
  133. local BestCustomer, BestDistance = nil, math.huge
  134. for _, Customer in next, Customers do
  135. if Customer:FindFirstChild("HumanoidRootPart") and LocalPlayer:DistanceFromCharacter(Customer.HumanoidRootPart.Position) < BestDistance then
  136. BestDistance = LocalPlayer:DistanceFromCharacter(Customer.HumanoidRootPart.Position)
  137. BestCustomer = Customer
  138. end
  139. end
  140.  
  141. return BestCustomer
  142. end
  143.  
  144. CashierClass.OrderConnection = workspace.GameService.RecivedCustomerOrder.OnClientEvent
  145.  
  146. function CashierClass:HandleCustomerDialog(Customer, Register)
  147. if FindChildByIndexSequence(Customer, {"Head", "DialogSimple", "Correct"}) and not CashierClass:IsInUse(Customer) then
  148. workspace:WaitForChild("Dialog"):FireServer("ClickedBubble", Customer.Head)
  149. workspace:WaitForChild("Dialog"):FireServer("ResponseSelected", Customer.Head.DialogSimple.Correct, Customer.Head)
  150.  
  151. local OrderString
  152. local ClientOrderConnection
  153.  
  154. ClientOrderConnection = self.OrderConnection:Connect(function(Order, ...)
  155. OrderString = Order
  156. ClientOrderConnection:Disconnect()
  157. end)
  158.  
  159. local TimeTaken = 0
  160.  
  161. repeat task.wait(0.1) TimeTaken += 0.1 until OrderString or TimeTaken >= self.Timeout
  162.  
  163. if TimeTaken >= self.Timeout then
  164. return
  165. end
  166.  
  167. Events.OrderComplete:FireServer(Customer, OrderString, Register)
  168. Customer:SetAttribute("AlreadyHandled", true)
  169.  
  170. print("Done handling dialog!")
  171. end
  172. end
  173.  
  174. function CashierClass:CustomerHasVisibleBubble(Customer)
  175. local Head = Customer:FindFirstChild("Head")
  176. local IsVisible = false
  177. for i,v in pairs(LocalPlayer.PlayerGui.CustomerBubbles:GetChildren()) do
  178. if v.Adornee == Head and v.Enabled == true then
  179. IsVisible = true
  180. end
  181. end
  182. if Customer.Head.SimpleDialogBillboard.Enabled == true then
  183. return false
  184. end
  185. return IsVisible
  186. end
  187.  
  188. function CashierClass:IsInUse(Customer)
  189. return FindChildByIndexSequence(Customer, {"Head", "InUse"}).Value and not CashierClass:CustomerHasVisibleBubble(Customer)
  190. end
  191.  
  192. local CashierCoroutine = coroutine.create(function()
  193. while wait(1) do
  194. print("Loop start")
  195. if LocalPlayer.Team ~= game:GetService("Teams").Cashier then
  196. TeleportToJob("Cashier")
  197. end
  198.  
  199. print('Getting closest customer')
  200. local ClosestCustomer = CashierClass:GetClosestValidCustomer()
  201. if ClosestCustomer then
  202. print('Getting register')
  203. local TargetRegister = CashierClass:GetRegisterFromCustomer(ClosestCustomer)
  204. if TargetRegister then
  205. print('Yielding for walking to finish')
  206. WalkToPoint(TargetRegister.Border.Position + (-TargetRegister.Border.CFrame.LookVector).Unit * 5)()
  207. LocalPlayer.Character:PivotTo(CFrame.new(LocalPlayer.Character.HumanoidRootPart.Position, ClosestCustomer.HumanoidRootPart.Position))
  208. if CashierClass:IsInUse(ClosestCustomer) then
  209. continue
  210. end
  211. print('Done yielding.')
  212. CashierClass:HandleCustomerDialog(ClosestCustomer, TargetRegister)
  213. print("Done order!")
  214. end
  215. end
  216. end
  217. end)
  218.  
  219. coroutine.resume(CashierCoroutine)
  220. MainClass:Init(true)
Add Comment
Please, Sign In to add comment