§ How to · with Picoo

How to make a Roblox boss fight (with AI)

By Sametcan Tasgiran, Founder & Developer·Published ·Updated

A Roblox boss needs a body that holds together, a health bar players can read, a way to find and chase them, a reason to keep their distance, and a death worth watching. Ask Picoo for a boss, a dragon, a golem or a titan and it applies its dramatic_boss recipe: one server Script that builds all five when the game starts.

1 file · 199 lines · one recipe call. Five color themes and a scale setting for titan-sized bosses.

Welded boss model

A Neon torso (14 × 16 × 8 studs), a glowing Neon head and two Granite arms, each joined to the torso with a WeldConstraint so the body moves as one piece. The scale param multiplies every part size and offset; 2.0 gives a titan with a 28-stud-wide torso.

Neon aura and five color themes

A PointLight with Range 40 on the torso gives the glow. color_theme picks dark_purple (the default), fire, ice, necrotic or blood, and recolors the body, the aura, the HP bar fill and the death particles.

Live HP bar over its head

A BillboardGui on the head shows the boss name over a fill bar, with current/max HP underneath. Humanoid.HealthChanged updates it on every hit, and AlwaysOnTop keeps it visible through walls.

Chase AI

Every half second the boss finds the closest player within chase_range (80 studs by default) and walks toward them with Humanoid:MoveTo at walk_speed 12.

Contact damage with a per-player cooldown

Touching the torso deals 35 damage through Humanoid:TakeDamage. A lastDamage table keyed by UserId gives each player one hit per damage_cooldown (1 second by default), so a player pressed against the boss loses at most 35 HP a second, not 35 HP every time Touched fires.

Death explosion

On Humanoid.Died the script creates an Explosion with BlastRadius 24 and DestroyJointRadiusPercent 0, so nearby players are knocked back but not killed. It then emits 150 particles in the theme colors, plays an explosion sound, and removes the boss 2 seconds later.

Files Picoo ships for this prompt

1 file · 199 lines · one recipe call

ServerScriptService/DarkOverlordSpawner.lua

Server Script that builds the boss, its HP bar, the chase loop, contact damage and the death effects. It is named after the boss: a boss called Dragon gets DragonSpawner.

199 lines

Sample output: ServerScriptService/DarkOverlordSpawner.lua

--!strict
-- Generated by Picoo recipe: dramatic_boss
-- ≥14 stud welded body, neon aura, HP bar, chase AI, death VFX

local Players = game:GetService("Players")
local Debris = game:GetService("Debris")

local BOSS_NAME = "DarkOverlord"
local BOSS_HEALTH = 2000
local BOSS_DAMAGE = 35
local CHASE_RANGE = 80
local DAMAGE_COOLDOWN = 1

-- (excerpt) inside spawnBoss(), after the body, aura, Humanoid and HP bar:

	-- Per-player damage debounce
	local lastDamage: { [number]: number } = {}
	torso.Touched:Connect(function(hit)
		local char = hit.Parent
		local h = char and char:FindFirstChildOfClass("Humanoid")
		if not h or h == humanoid then return end
		local player = Players:GetPlayerFromCharacter(char)
		if not player then return end
		local now = tick()
		if lastDamage[player.UserId] and (now - lastDamage[player.UserId]) < DAMAGE_COOLDOWN then return end
		lastDamage[player.UserId] = now
		h:TakeDamage(BOSS_DAMAGE)
	end)

	-- Chase AI — pursue closest player within range
	task.spawn(function()
		while humanoid.Health > 0 and boss.Parent do
			local closestRoot: BasePart? = nil
			local closestDistance = CHASE_RANGE
			for _, p in ipairs(Players:GetPlayers()) do
				local pChar = p.Character
				local pRoot = pChar and pChar:FindFirstChild("HumanoidRootPart") :: BasePart?
				if pRoot then
					local d = (pRoot.Position - hrp.Position).Magnitude
					if d < closestDistance then closestDistance = d; closestRoot = pRoot end
				end
			end
			if closestRoot then humanoid:MoveTo(closestRoot.Position) end
			task.wait(0.5)
		end
	end)

Building a Roblox boss fight

A boss is the set piece of a Roblox game, and it is where hand-written enemy code most often falls apart, sometimes literally: unanchored parts that are not welded to the body fall away from it. Picoo builds bosses from a fixed recipe, dramatic_boss, so the same settings produce the same working script every time.

The body is four visible parts plus an invisible HumanoidRootPart. The torso is 14 × 16 × 8 studs of Neon in the theme color, the head sits on top in a lighter Neon shade, and two Granite arms hang at the sides. Every part is joined to the torso with a WeldConstraint, and a PointLight with Range 40 lights the area around it. At the default scale the boss stands 24 studs tall; scale 2.0 doubles every part size and offset.

The HP bar is a 220 by 50 pixel BillboardGui on the head. The top half is the fill bar with the boss name over it in gold, and the bottom half shows current and max HP. It listens to Humanoid.HealthChanged, so it tracks damage from any weapon. Movement is a loop that runs every 0.5 seconds: it checks every player's HumanoidRootPart, picks the closest one inside chase_range, and calls Humanoid:MoveTo toward it. The Humanoid does the walking, and with AutoRotate on the boss turns to face where it is going.

Damage comes from touching the torso. Touched can fire many times while a player stays pressed against a part, so the script keeps a lastDamage table keyed by UserId and skips any hit that arrives before damage_cooldown has passed for that player. By default each player takes at most one 35-damage hit per second, however many players are in the fight, and only player characters take damage.

When the Humanoid dies, the script puts an Explosion at the torso with BlastRadius 24 and DestroyJointRadiusPercent 0, so nearby players are thrown back without being killed. It emits 150 particles in the theme colors, plays an explosion sound, and destroys the boss model two seconds later. Anything beyond that, such as a second phase, warning markers before an attack, a reward drop or a respawn timer, is a follow-up prompt away.

See more on the Luau generator, the AI Luau script writer, the 3D model generator and the game builder, read how Picoo compares with ChatGPT, or browse the full blog.

Frequently asked

What does Picoo build when I ask for a boss fight?+

One server Script, ServerScriptService/DarkOverlordSpawner with the default name. When the server starts it builds the boss model, gives it a Humanoid with 2,000 HP, attaches the HP bar, starts the chase loop, and wires up contact damage and the death effects. Give the boss a name and the script is named after it.

Can players fight back?+

Yes. The boss has a standard Humanoid, so anything that calls Humanoid:TakeDamage on it works, including Picoo's sword_tool and projectile_weapon recipes. The sword measures its reach to the boss's center, so for a titan-sized boss (scale 2) ask for a longer attack_range on the sword as well.

Can I change its health, damage and speed?+

Yes. Describe the boss you want and Picoo passes the matching values to the recipe: name, health (default 2000), damage (35), chase_range (80), damage_cooldown (1 second), walk_speed (12), scale (1.0), color_theme and spawn_position (default 0, 20, 0). 'A 5,000 HP fire dragon' covers health, name and color_theme.

Can I add phases, telegraphed attacks or loot drops?+

Yes, in a follow-up prompt. The recipe builds the boss itself: body, HP bar, chase, contact damage and death. Ask for the next layer on top of it, for example 'add a second phase below 50% HP that makes the boss faster' or 'drop a reward when the boss dies'.

When does the boss appear?+

When the game starts. The spawner is a Script in ServerScriptService, so it builds the boss at runtime and places it at spawn_position, which is 0, 20, 0 by default. Press Play in Studio to see it. The script spawns one boss per server; for a boss that comes back, ask for a respawn timer in a follow-up prompt.

Related Picoo prompts