Rec
Rec
LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local camera = workspace.CurrentCamera
local userInputService = game:GetService("UserInputService")
local virtualInputManager = game:GetService("VirtualInputManager")
-- Sort by distance
table.sort(distances, function(a, b)
return a.distance < b.distance
end)
-- Press R key
virtualInputManager:SendKeyEvent(true, "R", false, game)
task.wait(0.01)
virtualInputManager:SendKeyEvent(false, "R", false, game)
-- Turn function
local function turnCharacter()
local secondClosestGoal = getSecondClosestGoal()
if secondClosestGoal then
local characterPos = humanoidRootPart.Position
local direction = (characterPos - secondClosestGoal.Position).Unit
-- Input handler
userInputService.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed and input.KeyCode == Enum.KeyCode.X then
turnCharacter()
end
end)