ShoccessX

shooting sequence

Sep 15th, 2024 (edited)
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. -- Define the function to perform the sequence
  2. local function performSequence()
  3. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  4. local player = game.Players.LocalPlayer
  5. local character = player.Character or player.CharacterAdded:Wait()
  6. local humanoid = character:WaitForChild("Humanoid")
  7. local rootPart = character:WaitForChild("HumanoidRootPart")
  8.  
  9. -- Define the possible target positions
  10. local possibleTargetPositions1 = {
  11. Vector3.new(21, 4, -433),
  12. Vector3.new(-47, 4, -434),
  13. Vector3.new(21, 4, -408),
  14. Vector3.new(-47, 4, -409)
  15. }
  16.  
  17. local possibleTargetPositions2 = {
  18. Vector3.new(21, 4, -439),
  19. Vector3.new(-47, 4, -439),
  20. Vector3.new(21, 4, -403),
  21. Vector3.new(-47, 4, -404)
  22. }
  23.  
  24. -- Function to find the nearest position
  25. local function getNearestPosition(positions)
  26. local closestPosition = nil
  27. local shortestDistance = math.huge
  28.  
  29. for _, position in ipairs(positions) do
  30. local distance = (rootPart.Position - position).magnitude
  31. if distance < shortestDistance then
  32. shortestDistance = distance
  33. closestPosition = position
  34. end
  35. end
  36.  
  37. return closestPosition
  38. end
  39.  
  40. -- Function to walk to a position
  41. local function walkToPosition(position)
  42. print("Attempting to walk to position:", position) -- Debugging
  43. humanoid:MoveTo(position)
  44.  
  45. -- Wait for the humanoid to finish moving
  46. local moveToConnection
  47. local success = false
  48.  
  49. moveToConnection = humanoid.MoveToFinished:Connect(function(reached)
  50. success = reached
  51. end)
  52.  
  53. -- Wait for the move to finish or timeout after 10 seconds
  54. local timeout = tick() + 10
  55. repeat
  56. wait(0.1)
  57. until success or tick() > timeout
  58.  
  59. moveToConnection:Disconnect()
  60.  
  61. if success then
  62. print("Reached position:", position)
  63. else
  64. print("Failed to reach position:", position)
  65. end
  66. end
  67.  
  68. -- Main loop to execute the sequence
  69. local function mainLoop()
  70. -- Get the nearest positions from both sets
  71. local targetPosition1 = getNearestPosition(possibleTargetPositions1)
  72. local targetPosition2 = getNearestPosition(possibleTargetPositions2)
  73.  
  74. -- Print the nearest positions for debugging
  75. print("Nearest Position 1: ", targetPosition1)
  76. print("Nearest Position 2: ", targetPosition2)
  77.  
  78. -- Check if the positions are valid
  79. if not targetPosition1 then
  80. print("Error: The target position 1 is invalid.")
  81. return
  82. end
  83.  
  84. if not targetPosition2 then
  85. print("Error: The target position 2 is invalid.")
  86. return
  87. end
  88.  
  89. wait(5)
  90.  
  91. -- Walk to the first target position and shoot
  92. walkToPosition(targetPosition1)
  93.  
  94. wait(2)
  95.  
  96. local args1 = {
  97. [1] = true,
  98. [2] = "Shooting",
  99. [3] = "Standing Shot"
  100. }
  101. ReplicatedStorage:WaitForChild("PlayerEvents"):WaitForChild("Shooting"):FireServer(unpack(args1))
  102.  
  103. -- Wait for 2 seconds
  104. wait(2)
  105.  
  106. walkToPosition(targetPosition2)
  107.  
  108. wait(1)
  109.  
  110. -- Walk to the first target position again and shoot
  111. walkToPosition(targetPosition1)
  112.  
  113. wait(2)
  114.  
  115. local args2 = {
  116. [1] = true,
  117. [2] = "Shooting",
  118. [3] = "Standing Shot"
  119. }
  120. ReplicatedStorage:WaitForChild("PlayerEvents"):WaitForChild("Shooting"):FireServer(unpack(args2))
  121.  
  122. -- Wait for 2 seconds
  123. wait(2)
  124.  
  125. walkToPosition(targetPosition2)
  126.  
  127. wait(1)
  128.  
  129. -- Walk to the first target position a third time and shoot
  130. walkToPosition(targetPosition1)
  131.  
  132. wait(2)
  133.  
  134. local args3 = {
  135. [1] = true,
  136. [2] = "Shooting",
  137. [3] = "Layup"
  138. }
  139. ReplicatedStorage:WaitForChild("PlayerEvents"):WaitForChild("Shooting"):FireServer(unpack(args3))
  140.  
  141. -- Notify that the script has finished execution
  142. print("Reached the target position and completed the sequence.")
  143. end
  144.  
  145. -- Execute the main loop
  146. mainLoop()
  147. end
  148.  
  149. -- Run the performSequence function to start the process
  150. performSequence()
Advertisement
Add Comment
Please, Sign In to add comment