← KEMBALI KE SCRIPT LIBRARY

Naga

UmumVersi 1.0Update 25/11/2026

Naga Versi Lite

Cara penggunaan
Full Tutorial di YouTube iBalDBK
Lokasi pemasangan
Script di ServerScriptService
ScriptServerScriptService
-- Naga (versi ringkas). Script di ServerScriptService.
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local PLACE_NAME = "DragonPlace"
local SCALE = 0.8          -- ukuran naga
local FLY_HEIGHT = 5       -- tinggi terbang (kecil = rendah)
local CHASE_MARGIN = 30    -- jarak mengejar di luar tepi jalan
local DETECT_RANGE = 130   -- jarak naga bangun
local EDGE_MARGIN = 10
local FLY_SPEED = 45
local RETURN_SPEED = 30
local WALK_SPEED = 14
local TURN_SPEED = 2.2
local WALK_EVERY = 12      -- tiap sekian detik naga mendarat & berjalan
local WALK_TIME = 5
local ENABLE_FIRE = true
local FIRE_RANGE = 110
local FIRE_COOLDOWN = 3
local FIREBALL_SPEED = 75
local FIREBALL_DAMAGE = 25
local EXPLOSION_RADIUS = 10
local ENABLE_BITE = true
local BITE_RANGE = 18
local BITE_COOLDOWN = 2
local BITE_DAMAGE = 30

local S, V, CF = SCALE, Vector3.new, CFrame.Angles
local G = 9.5 * S
local RED, DARK, GOLD = Color3.fromRGB(175, 35, 45), Color3.fromRGB(50, 40, 50), Color3.fromRGB(235, 175, 45)
local GLOW, MEM, EYE = Color3.fromRGB(255, 110, 30), Color3.fromRGB(140, 25, 40), Color3.fromRGB(255, 230, 60)
local FACES = {"TopSurface", "BottomSurface", "LeftSurface", "RightSurface", "FrontSurface", "BackSurface"}
local NEON = Enum.Material.Neon

local function sm(a)
	a = math.clamp(a, 0, 1)
	return a * a * (3 - 2 * a)
end
local function wrap(a)
	return (a + math.pi) % (2 * math.pi) - math.pi
end

local place
for i = 1, 30 do
	place = workspace:FindFirstChild(PLACE_NAME, true)
	if place and place:IsA("BasePart") then
		break
	end
	place = nil
	task.wait(0.5)
end
if not place then
	warn("[Naga] Part DragonPlace tidak ditemukan")
	return
end

local folder = Instance.new("Folder")
folder.Name = "Dragon"
folder.Parent = workspace
local ballFolder = Instance.new("Folder")
ballFolder.Name = "Fireballs"
ballFolder.Parent = workspace

-- ===== MODEL =====
local spawnCF = place.CFrame * CFrame.new(0, place.Size.Y / 2 + G, 0)
local root = Instance.new("Part")
root.Size = V(1, 1, 1)
root.Transparency = 1
root.Anchored = true
root.CanCollide = false
root.CanTouch = false
root.CanQuery = false
root.CFrame = spawnCF
root.Parent = folder
local parts, rel, M, B = {Root = root}, {Root = CFrame.new()}, {}, {}

local function P(name, par, size, pos, col, joint, mir, mat)
	for _, n in ipairs(mir and {"L", "R"} or {""}) do
		local s = n == "L" and -1 or 1
		local pp = V(pos.X * s, pos.Y, pos.Z) * S
		local jp = pp
		if joint then
			jp = V(joint.X * s, joint.Y, joint.Z) * S
		end
		local pr = par
		if parts[par .. n] then
			pr = par .. n
		end
		local p = Instance.new("Part")
		p.Size = size * S
		p.Color = col
		p.Material = mat or Enum.Material.Plastic
		p.CanCollide = false
		p.CanTouch = false
		p.CanQuery = false
		p.Massless = true
		for _, f in ipairs(FACES) do
			p[f] = Enum.SurfaceType.Studs
		end
		local r = CFrame.new(pp)
		p.CFrame = spawnCF * r
		local m = Instance.new("Motor6D")
		m.Part0 = parts[pr]
		m.Part1 = p
		m.C0 = rel[pr]:Inverse() * CFrame.new(jp)
		m.C1 = r:Inverse() * CFrame.new(jp)
		m.Parent = p
		p.Parent = folder
		parts[name .. n], rel[name .. n], M[name .. n], B[name .. n] = p, r, m, m.C0
	end
end

P("Body", "Root", V(6, 5.5, 9), V(0, 0, 0), RED)
P("Belly", "Body", V(4, 1, 7), V(0, -2.7, 0), GOLD)
P("Core", "Body", V(1.6, 1.6, 0.4), V(0, 0.3, -4.6), GLOW, nil, false, NEON)
P("Neck1", "Body", V(3.4, 3.2, 3.6), V(0, 1.4, -6.2), RED, V(0, 1, -4.5))
P("Neck2", "Neck1", V(3, 3, 3.6), V(0, 2.9, -8.8), RED, V(0, 2.6, -7.2))
P("Head", "Neck2", V(3.8, 3.2, 4.6), V(0, 4.5, -11.6), RED, V(0, 3.8, -10.3))
P("Snout", "Head", V(2.4, 1.8, 3.2), V(0, 4, -15.2), RED)
P("Jaw", "Head", V(2.2, 0.8, 5), V(0, 3, -14), DARK, V(0, 3.3, -10.8))
P("Teeth", "Jaw", V(1.8, 0.5, 0.4), V(0, 3.6, -16), Color3.new(1, 1, 1))
P("Horn", "Head", V(0.7, 0.7, 2.4), V(1.3, 6.3, -10.2), GOLD, nil, true)
P("Eye", "Head", V(0.7, 0.5, 0.4), V(1.4, 5.6, -13.8), EYE, nil, true, NEON)
P("Tail1", "Body", V(4, 3.6, 4.5), V(0, -0.5, 6.5), RED, V(0, -0.3, 4.2))
P("Tail2", "Tail1", V(3, 2.8, 4.5), V(0, -0.8, 10.8), RED, V(0, -0.6, 8.6))
P("Tail3", "Tail2", V(2, 2, 4.5), V(0, -1, 15), DARK, V(0, -0.9, 13))
P("Tail4", "Tail3", V(1.2, 1.2, 4.5), V(0, -1.1, 19.2), GOLD, V(0, -1, 17.1))
P("Thigh", "Body", V(2.6, 4.4, 3.4), V(2.6, -3.6, 2), DARK, V(2.6, -1.6, 2), true)
P("Shin", "Thigh", V(2, 3.6, 2.6), V(2.6, -7, 2.6), RED, V(2.6, -5.6, 2.2), true)
P("Foot", "Shin", V(2.6, 0.9, 4), V(2.6, -9, 1.2), GOLD, V(2.6, -8.6, 2.4), true)
P("Arm", "Body", V(1.6, 3, 1.6), V(3.8, -1.5, -3), RED, V(3.5, -0.2, -3), true)
P("WingA", "Body", V(6, 0.9, 1.2), V(5.8, 2.4, -1), DARK, V(2.8, 2.3, -1), true)
P("MemA", "WingA", V(6, 0.25, 6), V(5.8, 2.25, 2.1), MEM, nil, true)
P("WingB", "WingA", V(7, 0.8, 1), V(12.3, 2.4, -1), DARK, V(8.8, 2.3, -1), true)
P("MemB", "WingB", V(7, 0.25, 5), V(12.3, 2.25, 1.5), MEM, nil, true)

-- ===== STATE =====
local d = {lx = 0, lz = 0, alt = 0, af = 0, yaw = 0, pitch = 0, roll = 0, st = "idle", stT = 0,
	after = "idle", actT = 0, done = false, lb = -99, lf = -99, nw = 0, wu = 0, spd = 0, t = 0,
	sp = 0, tk = 0, wk = 0, am = 0, fp = 0, wp = 0, na = 0, ha = 0, ja = 0, pAlt = 0, pYaw = 0, cf = spawnCF}
local balls = {}
local rp = RaycastParams.new()
rp.FilterType = Enum.RaycastFilterType.Exclude
rp.FilterDescendantsInstances = {folder, ballFolder}
rp.RespectCanCollide = true

local function hurt(pos, r, dmg)
	for _, pl in ipairs(Players:GetPlayers()) do
		local c = pl.Character
		local h = c and c:FindFirstChildOfClass("Humanoid")
		local hr = c and c:FindFirstChild("HumanoidRootPart")
		if h and hr and h.Health > 0 and (hr.Position - pos).Magnitude <= r then
			h:TakeDamage(dmg)
		end
	end
end

local function shoot()
	local from = (d.cf * CFrame.new(V(0, 4, -17.5) * S)).Position
	local dir = d.cf.LookVector
	if d.tg and d.tg.Parent then
		local aim = d.tg.Position + d.tg.AssemblyLinearVelocity * ((d.tg.Position - from).Magnitude / FIREBALL_SPEED)
		if (aim - from).Magnitude > 1 then
			dir = (aim - from).Unit
		end
	end
	local p = Instance.new("Part")
	p.Shape = Enum.PartType.Ball
	p.Size = V(3, 3, 3)
	p.Material = NEON
	p.Color = GLOW
	p.Anchored = true
	p.CanCollide = false
	p.CanTouch = false
	p.CanQuery = false
	p.CFrame = CFrame.new(from)
	Instance.new("PointLight", p).Range = 20
	Instance.new("Fire", p).Heat = 0
	p.Parent = ballFolder
	table.insert(balls, {part = p, pos = from, dir = dir, born = os.clock()})
end

local function bite()
	local head = (d.cf * CFrame.new(V(0, 4, -15) * S)).Position
	local h = d.tg and d.tg.Parent and d.tg.Parent:FindFirstChildOfClass("Humanoid")
	if h and h.Health > 0 and (d.tg.Position - head).Magnitude <= BITE_RANGE + 4 then
		h:TakeDamage(BITE_DAMAGE)
	end
end

local function target()
	local bh, bl, bd
	for _, pl in ipairs(Players:GetPlayers()) do
		local c = pl.Character
		local h = c and c:FindFirstChildOfClass("Humanoid")
		local hr = c and c:FindFirstChild("HumanoidRootPart")
		if h and hr and h.Health > 0 then
			local l = place.CFrame:PointToObjectSpace(hr.Position)
			if math.abs(l.X) <= place.Size.X / 2 + CHASE_MARGIN and math.abs(l.Z) <= place.Size.Z / 2 + CHASE_MARGIN and l.Y > -40 and l.Y < 80 then
				local dd = math.sqrt((l.X - d.lx) ^ 2 + (l.Z - d.lz) ^ 2)
				if not bd or dd < bd then
					bh, bl, bd = hr, l, dd
				end
			end
		end
	end
	return bh, bl, bd
end

local function face(x, z)
	return math.atan2(-(x - d.lx), -(z - d.lz))
end

-- ===== LOOP UTAMA =====
RunService.Heartbeat:Connect(function(dt)
	local now = os.clock()
	d.t = d.t + dt

	-- bola api
	for i = #balls, 1, -1 do
		local b = balls[i]
		local step = b.dir * FIREBALL_SPEED * dt
		local np = b.pos + step
		local boom = now - b.born > 5
		local r = workspace:Raycast(b.pos, step, rp)
		if r then
			np = r.Position
			boom = true
		end
		for _, pl in ipairs(Players:GetPlayers()) do
			local hr = pl.Character and pl.Character:FindFirstChild("HumanoidRootPart")
			if hr and (hr.Position - np).Magnitude <= 5 then
				boom = true
			end
		end
		if boom then
			local e = Instance.new("Explosion")
			e.Position = np
			e.BlastRadius = EXPLOSION_RADIUS
			e.BlastPressure = 0
			e.DestroyJointRadiusPercent = 0
			e.ExplosionType = Enum.ExplosionType.NoCraters
			e.Parent = workspace
			hurt(np, EXPLOSION_RADIUS, FIREBALL_DAMAGE)
			b.part:Destroy()
			table.remove(balls, i)
		else
			b.pos = np
			b.part.CFrame = CFrame.new(np)
		end
	end

	-- logika naga
	local hr, tl, td = target()
	local hx = math.max(0, place.Size.X / 2 - EDGE_MARGIN)
	local hz = math.max(0, place.Size.Z / 2 - EDGE_MARGIN)
	local gx, gz, spd, spread, amp, rate, atk = nil, nil, 0, 0, 0, 1, false
	local st = d.st

	if st == "idle" then
		d.yaw = d.yaw + wrap(-d.yaw) * math.min(1, dt)
		if hr and td <= DETECT_RANGE then
			d.st, d.stT, d.act, d.actT = "wake", 0, "roar", 0
		end
	elseif st == "wake" then
		d.stT = d.stT + dt
		spread = 0.3
		if tl then
			d.yaw = d.yaw + wrap(face(tl.X, tl.Z) - d.yaw) * math.min(1, dt * 2)
		end
		if d.stT > 1.3 then
			d.st, d.stT, d.af = "takeoff", 0, d.alt
		end
	elseif st == "takeoff" then
		d.stT = d.stT + dt
		local u = math.min(1, d.stT / 1.4)
		d.alt = d.af + (FLY_HEIGHT - d.af) * sm(u) + math.sin(math.pi * u) * 3
		spread, amp, rate = 1, 1.4, 1.5
		if tl then
			gx, gz, spd = tl.X, tl.Z, FLY_SPEED * 0.4
		end
		if u >= 1 then
			d.st, d.nw = "fly", now + WALK_EVERY + math.random() * 6
		end
	elseif st == "fly" then
		d.alt = FLY_HEIGHT
		spread, amp = 1, 1
		if hr then
			gx, gz, spd, atk = tl.X, tl.Z, FLY_SPEED * math.clamp(td / 25, 0.25, 1), true
			if now >= d.nw and not d.act and td < 70 then
				d.st, d.stT, d.after, d.af = "landing", 0, "walk", d.alt
			end
		else
			d.st = "return"
		end
	elseif st == "return" then
		d.alt = FLY_HEIGHT
		spread, amp = 1, 1
		if hr then
			d.st = "fly"
		else
			gx, gz, spd = 0, 0, RETURN_SPEED
			if d.lx ^ 2 + d.lz ^ 2 < 9 then
				d.st, d.stT, d.after, d.af = "landing", 0, "idle", d.alt
			end
		end
	elseif st == "landing" then
		d.stT = d.stT + dt
		local u = math.min(1, d.stT / 1.2)
		d.alt = d.af * (1 - sm(u)) + math.sin(math.pi * u) * 1.5
		spread, amp, rate = 1, 1.2, 1.3
		if d.after == "walk" and tl then
			gx, gz, spd = tl.X, tl.Z, 8
		end
		if u >= 1 then
			d.alt = 0
			if d.after == "walk" then
				d.st, d.stT, d.wu = "walk", 0, now + WALK_TIME
			else
				d.st = "idle"
			end
		end
	elseif st == "walk" then
		d.alt, spread = 0, 0.15
		if hr and now < d.wu then
			gx, gz, spd, atk = tl.X, tl.Z, WALK_SPEED * math.clamp(td / 15, 0.2, 1), true
		else
			d.st, d.stT, d.af = "takeoff", 0, d.alt
		end
	end

	-- memilih serangan
	if atk and not d.act then
		local head = (d.cf * CFrame.new(V(0, 4, -15) * S)).Position
		local ok = math.abs(wrap(face(tl.X, tl.Z) - d.yaw)) < 0.5
		if ENABLE_BITE and (hr.Position - head).Magnitude <= BITE_RANGE and now - d.lb >= BITE_COOLDOWN then
			d.act, d.actT, d.done, d.lb, d.tg = "bite", 0, false, now, hr
		elseif ENABLE_FIRE and td <= FIRE_RANGE and td > 8 and ok and now - d.lf >= FIRE_COOLDOWN then
			d.act, d.actT, d.done, d.lf, d.tg = "fire", 0, false, now, hr
		end
	end

	-- gerakan
	if d.act == "fire" or d.act == "bite" then
		spd = spd * 0.5
	elseif d.act == "roar" then
		spd = 0
	end
	d.spd = d.spd + (spd - d.spd) * math.min(1, dt * 2.5)
	if gx and (gx - d.lx) ^ 2 + (gz - d.lz) ^ 2 > 0.25 then
		local diff = wrap(face(gx, gz) - d.yaw)
		d.yaw = d.yaw + math.clamp(diff, -TURN_SPEED * dt, TURN_SPEED * dt)
		local v = d.spd * math.max(0.15, math.cos(diff))
		d.lx = d.lx - math.sin(d.yaw) * v * dt
		d.lz = d.lz - math.cos(d.yaw) * v * dt
	end
	d.lx = math.clamp(d.lx, -hx, hx)
	d.lz = math.clamp(d.lz, -hz, hz)

	-- animasi kepala (roar / fire / bite)
	local na, ha, ja = 0, 0, -0.04
	if d.act then
		d.actT = d.actT + dt
		if d.act == "roar" then
			local p = d.actT / 1.3
			local k = math.clamp(math.sin(math.pi * p) * 3, 0, 1)
			na, ha, ja = 0.55 * k, 0.4 * k, (-0.9 + math.sin(d.t * 25) * 0.08) * k
			if p >= 1 then
				d.act = nil
			end
		elseif d.act == "fire" then
			local p = d.actT
			if p < 0.55 then
				local k = sm(p / 0.55)
				na, ha, ja = 0.4 * k, 0.3 * k, -0.9 * k
			else
				if not d.done then
					d.done = true
					shoot()
				end
				local k = sm((p - 0.55) / 0.45)
				na, ha, ja = -0.15 * (1 - k), -0.1 * (1 - k), -0.9 * (1 - sm((p - 0.7) / 0.3))
			end
			if p >= 1 then
				d.act = nil
			end
		else
			local p = d.actT / 0.8
			if p < 0.4 then
				local k = sm(p / 0.4)
				na, ha, ja = -0.35 * k, -0.2 * k, -k
			else
				if not d.done then
					d.done = true
					bite()
				end
				local k = 1 - sm((p - 0.5) / 0.5)
				na, ha, ja = -0.35 * k, -0.2 * k, 0
			end
			if p >= 1 then
				d.act = nil
			end
		end
	end

	-- penghalus animasi
	local k4 = math.min(1, dt * 4)
	local k12 = math.min(1, dt * 12)
	d.sp = d.sp + (spread - d.sp) * k4
	d.tk = d.tk + (math.clamp(d.alt / math.max(FLY_HEIGHT, 0.1), 0, 1) - d.tk) * k4
	local walkT = 0
	if d.alt < 0.5 then
		walkT = math.clamp(d.spd / WALK_SPEED, 0, 1)
	end
	d.wk = d.wk + (walkT - d.wk) * k4
	d.am = d.am + (amp - d.am) * k4
	d.fp = d.fp + dt * 7 * rate
	d.wp = d.wp + dt * d.spd * 0.4
	d.na = d.na + (na - d.na) * k12
	d.ha = d.ha + (ha - d.ha) * k12
	d.ja = d.ja + (ja - d.ja) * math.min(1, dt * 18)
	local air = d.tk
	local pitchT = math.clamp((d.alt - d.pAlt) / dt * 0.05, -0.35, 0.45) - 0.12 * d.spd / FLY_SPEED * air
	local rollT = math.clamp(wrap(d.yaw - d.pYaw) / dt * 0.18, -0.35, 0.35) * air
	d.pitch = d.pitch + (pitchT - d.pitch) * k4
	d.roll = d.roll + (rollT - d.roll) * k4
	d.pAlt, d.pYaw = d.alt, d.yaw

	-- posisi
	local y = place.Size.Y / 2 + G + d.alt + math.sin(d.t * 1.6) * 0.6 * S * air
	d.cf = place.CFrame * CFrame.new(d.lx, y, d.lz) * CF(0, d.yaw, 0) * CF(d.pitch, 0, d.roll)
	root.CFrame = d.cf

	-- sendi-sendi
	local t, sp, br = d.t, d.sp, math.sin(d.t * 1.5)
	local look = 0
	if st == "idle" then
		look = math.sin(t * 0.4) * 0.4
	end
	M.Body.C0 = B.Body * CFrame.new(0, (br * 0.15 + math.cos(d.fp) * 0.35 * d.am * air) * S, 0)
	M.Neck1.C0 = B.Neck1 * CF(d.na * 0.5 + br * 0.03, look * 0.4, 0)
	M.Neck2.C0 = B.Neck2 * CF(d.na * 0.5, look * 0.4, 0)
	M.Head.C0 = B.Head * CF(d.ha - 0.05 * air, look * 0.2, 0)
	M.Jaw.C0 = B.Jaw * CF(d.ja, 0, 0)
	for i = 1, 4 do
		local w = math.sin(t * (2 + air * 1.5) - i * 0.7) * (0.08 + 0.1 * air + 0.06 * d.wk) * (0.5 + 0.2 * i)
		M["Tail" .. i].C0 = B["Tail" .. i] * CF(-0.06 * air, w, 0)
	end
	for _, n in ipairs({"L", "R"}) do
		local s = n == "L" and -1 or 1
		local a = (1 - sp) + 0.15 * sp + math.sin(d.fp) * 0.55 * d.am * sp
		local b = -1.7 * (1 - sp) + 0.1 * sp + math.sin(d.fp - 0.8) * 0.45 * d.am * sp
		M["WingA" .. n].C0 = B["WingA" .. n] * CF(0, -s * 0.9 * (1 - sp), s * a)
		M["WingB" .. n].C0 = B["WingB" .. n] * CF(0, 0, s * b)
		local ph = d.wp
		if s == 1 then
			ph = d.wp + math.pi
		end
		local sw = math.sin(ph) * 0.55 * d.wk
		local th = -0.7 * air + sw
		local sh = -air - math.max(0, math.sin(ph + 1.2)) * 0.9 * d.wk
		M["Thigh" .. n].C0 = B["Thigh" .. n] * CF(th, 0, 0)
		M["Shin" .. n].C0 = B["Shin" .. n] * CF(sh, 0, 0)
		M["Foot" .. n].C0 = B["Foot" .. n] * CF(-(th + sh) * 0.8, 0, 0)
		M["Arm" .. n].C0 = B["Arm" .. n] * CF(-0.8 * air - sw * 0.5, 0, 0)
	end
end)