0% found this document useful (0 votes)
1K views3 pages

Script Zombie Attack

This document contains a Lua script for a Roblox game that implements an auto-farming feature. It includes a GUI with a toggle button to enable or disable farming, automatic targeting of enemies, and shooting mechanics. The script utilizes functions to find the nearest target, calculate positions for movement and shooting, and manages the camera view accordingly.

Uploaded by

amelialandan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views3 pages

Script Zombie Attack

This document contains a Lua script for a Roblox game that implements an auto-farming feature. It includes a GUI with a toggle button to enable or disable farming, automatic targeting of enemies, and shooting mechanics. The script utilizes functions to find the nearest target, calculate positions for movement and shooting, and manages the camera view accordingly.

Uploaded by

amelialandan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

local Player = game.Players.

LocalPlayer
local Camera = workspace.CurrentCamera
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local farmEnabled = false


local currentTarget = nil
local angle = 0

-- GUI
local screenGui = Instance.new("ScreenGui", Player:WaitForChild("PlayerGui"))
screenGui.Name = "AutoFarmGUI"
screenGui.ResetOnSpawn = false

local button = Instance.new("TextButton", screenGui)


button.Size = UDim2.new(0, 100, 0, 40)
button.Position = UDim2.new(0.4, 0, 0.1, 0)
button.Text = "Off"
button.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
button.TextColor3 = Color3.new(1,1,1)
button.Font = Enum.Font.SourceSansBold
button.TextSize = 24
button.BorderSizePixel = 0
button.BackgroundTransparency = 0.1
button.AutoButtonColor = false
button.Active = true
button.Draggable = true

local uicorner = Instance.new("UICorner", button)


uicorner.CornerRadius = UDim.new(0, 8)

local uistroke = Instance.new("UIStroke", button)


uistroke.Thickness = 2
uistroke.Color = Color3.fromRGB(255, 0, 0)
uistroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Border

button.MouseButton1Click:Connect(function()
farmEnabled = not farmEnabled
if farmEnabled then
button.Text = "On"
button.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
uistroke.Color = Color3.fromRGB(0, 255, 0)
else
button.Text = "Off"
button.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
uistroke.Color = Color3.fromRGB(255, 0, 0)
end
end)

-- 🧠 Detectar parte válida do inimigo


local function getValidPart(enemy)
return enemy:FindFirstChild("Head") or
enemy:FindFirstChild("HumanoidRootPart") or enemy:FindFirstChild("Torso") or
enemy:FindFirstChild("UpperTorso") or enemy.PrimaryPart
end

-- 🎯 Buscar alvo mais próximo (Boss > Zumbis)


local function getNearestTarget()
local nearest, dist = nil, math.huge
-- Bosses (qualquer pasta com "boss" no nome)
for _, folder in pairs(workspace:GetChildren()) do
if folder:IsA("Folder") and string.lower(folder.Name):find("boss") then
for _, boss in pairs(folder:GetChildren()) do
local part = getValidPart(boss)
if part then
local mag =
(Player.Character.HumanoidRootPart.Position - part.Position).Magnitude
if mag < dist then
dist = mag
nearest = boss
end
end
end
end
end

-- Inimigos normais
local enemies = workspace:FindFirstChild("enemies")
if enemies then
for _, enemy in pairs(enemies:GetChildren()) do
local part = getValidPart(enemy)
if part then
local mag = (Player.Character.HumanoidRootPart.Position -
part.Position).Magnitude
if mag < dist then
dist = mag
nearest = enemy
end
end
end
end

return nearest
end

-- 📌 Gira acima do inimigo (anti-torre) com altura maior


local function getAbovePosition(target)
local part = getValidPart(target)
if part then
angle += 0.05
local radius = 6
local x = math.cos(angle) * radius
local z = math.sin(angle) * radius
return part.CFrame * CFrame.new(x, 25, z) -- ← Altura agora é 25 (mais
proteção)
end
return Player.Character.HumanoidRootPart.CFrame
end

-- 📌 Teleporte frontal para disparar


local function getShootPosition(target)
local part = getValidPart(target)
if part then
return part.CFrame * CFrame.new(0, 6, 7)
end
return Player.Character.HumanoidRootPart.CFrame
end
-- Movimento automático
RunService.RenderStepped:Connect(function()
if farmEnabled and Player.Character and
Player.Character:FindFirstChild("HumanoidRootPart") then
local target = getNearestTarget()
if target then
currentTarget = target
Player.Character.HumanoidRootPart.CFrame =
getAbovePosition(target)
local part = getValidPart(target)
if part then
Camera.CFrame = CFrame.new(Camera.CFrame.Position,
part.Position)
end
end
end
end)

-- Disparo com teleporte


task.spawn(function()
while true do
task.wait(0.2)
if farmEnabled and currentTarget and
Player.Character:FindFirstChildOfClass("Tool") then
local tool = Player.Character:FindFirstChildOfClass("Tool")
local part = getValidPart(currentTarget)
if tool and part then
local originalPos =
Player.Character.HumanoidRootPart.CFrame
Player.Character.HumanoidRootPart.CFrame =
getShootPosition(currentTarget)

ReplicatedStorage.Gun:FireServer({
["Normal"] = Vector3.zero,
["Direction"] = part.Position,
["Name"] = tool.Name,
["Hit"] = part,
["Origin"] = Player.Character.Head.Position,
["Pos"] = part.Position
})

Player.Character.HumanoidRootPart.CFrame = originalPos
end
end
end
end)

You might also like