Dungeon Quest Script | AUTOFARM

Created by For

Features:

basically you load into a dungeon with your starter/whatever spells equipped and then click start dungeon button and then u execute this script.
if enough people want it, i’ll update the code to be used with a ui, a full dungeon starting autofarm, and make it actually work better, or someone else can do it.

local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer

local function getAttackRemotes()
    local remotes = {}
    for _,tool in next, localPlayer.Backpack:GetChildren() do
        table.insert(remotes, tool:FindFirstChildOfClass("RemoteEvent"))
    end
    for _,v in next, localPlayer.Character:GetDescendants() do
        if v.Name == "swing" and v:IsA("RemoteEvent") then
            table.insert(remotes, v)
        end
    end
    return remotes
end

local attackRemotes = getAttackRemotes()

local function enemyFolder()
    for _,v in next, workspace.dungeon:GetDescendants() do
        if v.Parent.Name == "enemyFolder" and v:IsA("Model") then
            return v.Parent
        end
    end
end

local function killCluster()
    local rootPart = game.Players.LocalPlayer.Character.HumanoidRootPart
    local old_cframe = rootPart.CFrame
    local enemyF = enemyFolder()
    local enemyRootPart = enemyF:FindFirstChildOfClass("Model").HumanoidRootPart
    local safeDis = enemyF.Parent.Name == "bossRoom" and 50 or 20
    
    rootPart.CFrame = CFrame.lookAt(
        Vector3.new(
            enemyRootPart.Position.X + safeDis,
            enemyRootPart.Position.Y,
            enemyRootPart.Position.Z
            ), enemyRootPart.Position)
        
    rootPart.Anchored = false
    task.wait(.2)
    rootPart.Anchored = true
    rootPart.CFrame = enemyRootPart.CFrame --+ Vector3.new(0,8,0)
    
    print("Waiting three seconds.")
    task.wait(3) 
    print("Starting attack.")
    repeat
        for _,remote in next, attackRemotes do
            remote:FireServer()
        end
        task.wait(.2)
    until enemyRootPart.Parent == nil or enemyRootPart.Parent.Humanoid.Health == 0
    print("Target enemy killed.")
    task.wait(1.5)
    killCluster()
end

killCluster()

-- yoinked l0l
local PlayerModule = localPlayer.PlayerScripts:WaitForChild("PlayerModule")
local Cameras = require(PlayerModule):GetCameras()
local CameraController = Cameras.activeCameraController
local MouseLockController = Cameras.activeMouseLockController


game:GetService("UserInputService").InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.LeftShift or Input.KeyCode == Enum.KeyCode.RightShift then
MouseLockController:OnMouseLockToggled()
CameraController:SetIsMouseLocked(false)
end
end)