Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local player = game.Players.LocalPlayer -- ตัวแปรผู้เล่นหลัก
- local character = player.Character -- ตัวแปรตัวละครของผู้เล่น
- local localroot = character.HumanoidRootPart -- หัวส่วนหลักของตัวละคร
- local UIS = game:GetService("UserInputService") -- บริการตรวจจับการกดแป้นพิมพ์
- local Camera = workspace.CurrentCamera -- กล้องหลักในเกม
- local function closestPlayer() -- ฟังก์ชันหาผู้เล่นที่ใกล้ที่สุด
- local target = nil -- เริ่มต้นเป้าหมายเป็นค่าว่าง
- local range = math.huge -- กำหนดช่วงเป็นค่าสุดขีด
- for _, v in pairs(game.Players:GetPlayers()) do -- วนลูปผ่านผู้เล่นทั้งหมดในเกม
- if v ~= player and v.Character then -- ถ้าผู้เล่นไม่ใช่ตัวเองและมีตัวละคร
- local JN = v.Character:FindFirstChild("HumanoidRootPart") -- หา HumanoidRootPart ของผู้เล่น
- if JN then
- local distance = (localroot.Position - JN.Position).magnitude -- คำนวณระยะห่างระหว่างตัวเองกับผู้เล่นอื่น
- if distance < range then -- ถ้าระยะห่างน้อยกว่าช่วงที่กำหนด
- range = distance -- กำหนดช่วงใหม่เป็นระยะห่างนั้น
- target = v -- กำหนดเป้าหมายเป็นผู้เล่นนั้น
- end
- end
- end
- end
- return target -- คืนค่าผู้เล่นที่ใกล้ที่สุด
- end
- local aimbot = false -- กำหนดสถานะ aimbot เป็นปิด
- UIS.InputBegan:Connect(function(input) -- ฟังก์ชันที่ทำงานเมื่อมีการกดแป้นพิมพ์
- if input.KeyCode == Enum.KeyCode.P then -- ถ้ากดแป้น P
- aimbot = not aimbot -- สลับสถานะ aimbot
- if aimbot then -- ถ้า aimbot เปิด
- spawn(function()
- while aimbot == true do -- วนลูปตราบเท่าที่ aimbot เปิด
- if aimbot ~= true then return end -- ถ้า aimbot ปิด ให้ออกจากลูป
- local Enemy = closestPlayer() -- หาเป้าหมายที่ใกล้ที่สุด
- if Enemy and Enemy.Character then -- ถ้าเจอเป้าหมายและมีตัวละคร
- local EnemyV = Enemy.Character:FindFirstChild("HumanoidRootPart") -- หา HumanoidRootPart ของเป้าหมาย
- local EnemyK = Enemy.Character:FindFirstChild("Humanoid") -- หา Humanoid ของเป้าหมาย
- if EnemyV and EnemyK and EnemyK.Health > 0 then -- ถ้าเจอ HumanoidRootPart และ Humanoid ของเป้าหมายและสุขภาพมากกว่า 0
- Camera.CFrame = CFrame.new(Camera.CFrame.Position, EnemyV.Position) -- ตั้งกล้องให้หันไปทางเป้าหมาย
- end
- end
- game:GetService("RunService").Heartbeat:Wait() -- รอจนกว่าเฟรมถัดไป
- end
- end)
- end
- elseif input.KeyCode == Enum.KeyCode.K then -- ถ้ากดแป้น K
- aimbot = false -- ปิด aimbot
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment