-- Dungeon Leveling AutoFarm (ปรับให้ปลอดภัยจากศัตรู)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local humanoid = character:FindFirstChildOfClass("Humanoid")
local runService = game:GetService("RunService")
local userInput = game:GetService("UserInputService")
local autoFarm = true
local HIT_RANGE = 10
-- ป้องกันการถูกตีโดยย้ายตัวละครขึ้นสูง
local function moveCharacterOutOfRange()
if humanoidRootPart then
humanoidRootPart.Anchored = true
humanoidRootPart.Position = Vector3.new(0, 9999, 0)
workspace.CurrentCamera.CameraSubject = humanoid
print("✅ ปลอดภัยจากศัตรูแล้ว")
end
end
local function getClosestMob()
local closestMob = nil
local closestDistance = math.huge
for _, mob in ipairs(workspace.Characters:GetChildren()) do
if mob:IsA("Model") and mob ~= character and mob:FindFirstChild("HumanoidRootPart") then
local dist = (mob.HumanoidRootPart.Position - humanoidRootPart.Position).Magnitude
if dist < closestDistance then
closestDistance = dist
closestMob = mob
end
end
end
return closestMob
end
local function isInRange(mob, range)
local mobRootPart = mob:FindFirstChild("HumanoidRootPart")
if not mobRootPart or not humanoidRootPart then return false end
return (mobRootPart.Position - humanoidRootPart.Position).Magnitude <= range
end
local function equipWeapon()
local eventFolder = game:GetService("ReplicatedStorage"):FindFirstChild("Events")
if eventFolder and eventFolder:FindFirstChild("WeaponsEvent") then
eventFolder.WeaponsEvent:FireServer("Equip/UnEquip")
end
end
equipWeapon()
local function useSkill(skillName)
local eventFolder = game:GetService("ReplicatedStorage"):FindFirstChild("Events")
if eventFolder and eventFolder:FindFirstChild("Skill") then
eventFolder.Skill:FireServer({ Skill = skillName, Function = "Activate" }, humanoidRootPart.Position, true)
end
end
local function attack()
while autoFarm do
local mob = getClosestMob()
if mob then
-- โจมตีโดยไม่เข้าใกล้
local eventFolder = game:GetService("ReplicatedStorage"):FindFirstChild("Events")
if eventFolder and eventFolder:FindFirstChild("Combat") then
eventFolder.Combat:FireServer("Attack")
end
useSkill("FlurryOfBlows")
useSkill("BloodyCut")
useSkill("Invisibility")
end
task.wait(0.5)
end
end
local function stopAutoFarm()
autoFarm = false
humanoidRootPart.Anchored = false
end
local function enableNoFall()
runService.Stepped:Connect(function()
if autoFarm and humanoidRootPart then
humanoidRootPart.Velocity = Vector3.new(0, 0, 0)
end
end)
end
enableNoFall()
moveCharacterOutOfRange()
userInput.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed and input.KeyCode == Enum.KeyCode.Zero then
stopAutoFarm()
end
end)
attack()