Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define the function to perform the sequence
- local function performSequence()
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local player = game.Players.LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- local rootPart = character:WaitForChild("HumanoidRootPart")
- -- Define the possible target positions
- local possibleTargetPositions1 = {
- Vector3.new(21, 4, -433),
- Vector3.new(-47, 4, -434),
- Vector3.new(21, 4, -408),
- Vector3.new(-47, 4, -409)
- }
- local possibleTargetPositions2 = {
- Vector3.new(21, 4, -439),
- Vector3.new(-47, 4, -439),
- Vector3.new(21, 4, -403),
- Vector3.new(-47, 4, -404)
- }
- -- Function to find the nearest position
- local function getNearestPosition(positions)
- local closestPosition = nil
- local shortestDistance = math.huge
- for _, position in ipairs(positions) do
- local distance = (rootPart.Position - position).magnitude
- if distance < shortestDistance then
- shortestDistance = distance
- closestPosition = position
- end
- end
- return closestPosition
- end
- -- Function to walk to a position
- local function walkToPosition(position)
- print("Attempting to walk to position:", position) -- Debugging
- humanoid:MoveTo(position)
- -- Wait for the humanoid to finish moving
- local moveToConnection
- local success = false
- moveToConnection = humanoid.MoveToFinished:Connect(function(reached)
- success = reached
- end)
- -- Wait for the move to finish or timeout after 10 seconds
- local timeout = tick() + 10
- repeat
- wait(0.1)
- until success or tick() > timeout
- moveToConnection:Disconnect()
- if success then
- print("Reached position:", position)
- else
- print("Failed to reach position:", position)
- end
- end
- -- Main loop to execute the sequence
- local function mainLoop()
- -- Get the nearest positions from both sets
- local targetPosition1 = getNearestPosition(possibleTargetPositions1)
- local targetPosition2 = getNearestPosition(possibleTargetPositions2)
- -- Print the nearest positions for debugging
- print("Nearest Position 1: ", targetPosition1)
- print("Nearest Position 2: ", targetPosition2)
- -- Check if the positions are valid
- if not targetPosition1 then
- print("Error: The target position 1 is invalid.")
- return
- end
- if not targetPosition2 then
- print("Error: The target position 2 is invalid.")
- return
- end
- wait(5)
- -- Walk to the first target position and shoot
- walkToPosition(targetPosition1)
- wait(2)
- local args1 = {
- [1] = true,
- [2] = "Shooting",
- [3] = "Standing Shot"
- }
- ReplicatedStorage:WaitForChild("PlayerEvents"):WaitForChild("Shooting"):FireServer(unpack(args1))
- -- Wait for 2 seconds
- wait(2)
- walkToPosition(targetPosition2)
- wait(1)
- -- Walk to the first target position again and shoot
- walkToPosition(targetPosition1)
- wait(2)
- local args2 = {
- [1] = true,
- [2] = "Shooting",
- [3] = "Standing Shot"
- }
- ReplicatedStorage:WaitForChild("PlayerEvents"):WaitForChild("Shooting"):FireServer(unpack(args2))
- -- Wait for 2 seconds
- wait(2)
- walkToPosition(targetPosition2)
- wait(1)
- -- Walk to the first target position a third time and shoot
- walkToPosition(targetPosition1)
- wait(2)
- local args3 = {
- [1] = true,
- [2] = "Shooting",
- [3] = "Layup"
- }
- ReplicatedStorage:WaitForChild("PlayerEvents"):WaitForChild("Shooting"):FireServer(unpack(args3))
- -- Notify that the script has finished execution
- print("Reached the target position and completed the sequence.")
- end
- -- Execute the main loop
- mainLoop()
- end
- -- Run the performSequence function to start the process
- performSequence()
Advertisement
Add Comment
Please, Sign In to add comment