← KEMBALI KE SCRIPT LIBRARY

Semua Buaya (Crocodile)

UmumVersi 1.0Update 25/11/2026

Disini crocodile nya ada beberapa versi , versi 1 , versi 2 dan seterusnya . Jadi kalian bisa cek di script ini .

Cara penggunaan
Full Tutorial di YouTube iBalDBK
Lokasi pemasangan
Taruh sebagai Script (BUKAN LocalScript) di ServerScriptService
ScriptVersi 1
-- CrocodileSpawner (versi hiasan: DECORATION_ONLY = true)
-- Taruh sebagai Script (BUKAN LocalScript) di ServerScriptService.
-- Buaya stud berenang di Part bernama "water" (di dalam folder water kill),
-- melompat menggigit pemain yang lewat di dekatnya, dan kebal terhadap water kill.

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

-- ===================== PENGATURAN =====================
local CROC_COUNT = 8           -- jumlah buaya (5 - 10)
local CROC_SCALE = 0.8         -- UKURAN buaya (0.5 = kecil, 1 = besar)

local WATER_FOLDER_NAME = ""   -- nama folder water kill ("" = cari otomatis folder yang namanya mengandung "water")
local WATER_PART_NAME = "water" -- nama Part air di dalam folder (huruf besar/kecil bebas)

local SWIM_SPEED = 6           -- kecepatan berenang santai
local STALK_SPEED = 14         -- kecepatan berenang saat mengincar pemain
local TURN_SPEED = 2.5         -- kecepatan berbelok
local EDGE_MARGIN = 4          -- jarak aman dari tepi air (supaya buaya tidak keluar dari air)

local DECORATION_ONLY = true    -- true = buaya HANYA hiasan: tidak mengincar, tidak melompat, tidak memberi damage
local DETECT_RANGE = 60        -- jarak buaya mulai mengincar pemain
local ENABLE_JUMP = true       -- true = buaya bisa melompat menyerang
local JUMP_RANGE = 38          -- jarak pemain agar buaya melompat
local JUMP_HEIGHT = 12         -- tinggi lompatan
local LEAP_TIME = 0.9          -- lama lompatan (detik)
local WINDUP_TIME = 0.45       -- lama bersiap sebelum melompat
local RECOVER_TIME = 0.6       -- lama diam setelah mendarat sebelum kembali ke air
local JUMP_COOLDOWN = 5        -- jeda antar lompatan (detik)
local DAMAGE = 30              -- damage gigitan
local HIT_RADIUS = 10          -- jarak gigitan kena pemain

local STUDS_ALL_SIDES = true

local GREEN = Color3.fromRGB(70, 105, 50)
local DARK = Color3.fromRGB(45, 75, 38)
local BELLY = Color3.fromRGB(190, 185, 120)
local TOOTH = Color3.fromRGB(255, 255, 255)
local EYEC = Color3.fromRGB(255, 200, 40)
local BLACK = Color3.fromRGB(15, 15, 15)
-- ======================================================

local S = CROC_SCALE
local V = Vector3.new
local FLOAT = 0.15             -- seberapa tinggi badan dari permukaan air
local VERTICAL_RANGE = 30
local SURFACES = {"TopSurface", "BottomSurface", "LeftSurface", "RightSurface", "FrontSurface", "BackSurface"}

local function rand(a, b)
	return a + math.random() * (b - a)
end

local function wrapAngle(a)
	while a > math.pi do
		a = a - 2 * math.pi
	end
	while a < -math.pi do
		a = a + 2 * math.pi
	end
	return a
end

-- ============ MENCARI PART WATER ============
local function findFolder()
	if WATER_FOLDER_NAME ~= "" then
		return workspace:FindFirstChild(WATER_FOLDER_NAME, true)
	end
	for _, c in ipairs(workspace:GetChildren()) do
		if c:IsA("Folder") or c:IsA("Model") then
			if string.find(string.lower(c.Name), "water") then
				return c
			end
		end
	end
	return nil
end

local function collectWaters()
	local root = findFolder()
	if root == nil then
		warn("[Buaya] Folder water tidak ditemukan. Mencari Part '" .. WATER_PART_NAME .. "' di seluruh Workspace.")
		root = workspace
	else
		print("[Buaya] Folder water ditemukan:", root.Name)
	end
	local list = {}
	local want = string.lower(WATER_PART_NAME)
	for _, d in ipairs(root:GetDescendants()) do
		if d:IsA("BasePart") and string.lower(d.Name) == want then
			table.insert(list, d)
		end
	end
	return list
end

task.wait(1)
local waters = collectWaters()
if #waters == 0 then
	warn("[Buaya] Tidak ada Part air yang ditemukan. Cek WATER_FOLDER_NAME dan WATER_PART_NAME.")
	return
end
print("[Buaya] Jumlah Part air:", #waters)

local totalArea = 0
for _, w in ipairs(waters) do
	totalArea = totalArea + w.Size.X * w.Size.Z
end

local function pickWater()
	local r = math.random() * totalArea
	for _, w in ipairs(waters) do
		r = r - w.Size.X * w.Size.Z
		if r <= 0 then
			return w
		end
	end
	return waters[#waters]
end

local crocFolder = Instance.new("Folder")
crocFolder.Name = "Crocodiles"
crocFolder.Parent = workspace

-- ============ MEMBANGUN BUAYA ============
local function sc(cf)
	return CFrame.new(cf.Position * S) * (cf - cf.Position)
end

local function buildCroc(spawnCFrame)
	local model = Instance.new("Model")
	model.Name = "Crocodile"

	local root = Instance.new("Part")
	root.Name = "Root"
	root.Size = V(1, 1, 1) * S
	root.Transparency = 1
	root.Anchored = true
	root.CanCollide = false
	root.CanTouch = false
	root.CanQuery = false
	root.CFrame = spawnCFrame
	root.Parent = model
	model.PrimaryPart = root

	local parts = {Root = root}
	local rels = {Root = CFrame.new()}
	local M = {}
	local B = {}

	local function add(name, size, cf, color, parent, joint)
		local rel = sc(cf)
		local p = Instance.new("Part")
		p.Name = name
		p.Size = size * S
		p.Color = color
		p.Material = Enum.Material.Plastic
		p.CanCollide = false
		p.CanTouch = false
		p.CanQuery = false
		p.Massless = true
		p.CFrame = spawnCFrame * rel
		for _, s in ipairs(SURFACES) do
			if STUDS_ALL_SIDES or s == "TopSurface" then
				p[s] = Enum.SurfaceType.Studs
			else
				p[s] = Enum.SurfaceType.Smooth
			end
		end
		local jointPos = joint
		if jointPos == nil then
			jointPos = cf.Position
		end
		local jointCF = CFrame.new(jointPos * S)
		local m = Instance.new("Motor6D")
		m.Name = name
		m.Part0 = parts[parent]
		m.Part1 = p
		m.C0 = rels[parent]:Inverse() * jointCF
		m.C1 = rel:Inverse() * jointCF
		m.Parent = p
		p.Parent = model
		parts[name] = p
		rels[name] = rel
		M[name] = m
		B[name] = m.C0
		return p
	end

	-- Badan
	add("Body", V(4, 1.6, 6), CFrame.new(0, 0.2, 0), GREEN, "Root", V(0, 0, 0))
	add("Belly", V(3.2, 0.4, 5.4), CFrame.new(0, -0.65, 0), BELLY, "Body")
	local scuteZ = {-1.8, 0, 1.8}
	for i = 1, #scuteZ do
		add("ScuteL" .. i, V(0.7, 0.5, 0.9), CFrame.new(-1, 1.25, scuteZ[i]), DARK, "Body")
		add("ScuteR" .. i, V(0.7, 0.5, 0.9), CFrame.new(1, 1.25, scuteZ[i]), DARK, "Body")
	end

	-- Kaki pendek
	local sides = {{"L", -1}, {"R", 1}}
	for _, sd in ipairs(sides) do
		local n = sd[1]
		local s = sd[2]
		add("LegF" .. n, V(1.2, 0.5, 1.8), CFrame.new(2.5 * s, -0.2, -2), DARK, "Body", V(2 * s, -0.2, -2))
		add("LegB" .. n, V(1.2, 0.5, 1.8), CFrame.new(2.5 * s, -0.2, 2.5), DARK, "Body", V(2 * s, -0.2, 2.5))
	end

	-- Kepala, moncong, rahang
	add("Head", V(3, 1.2, 3.5), CFrame.new(0, 0.25, -4.4), GREEN, "Body", V(0, 0.25, -3))
	add("Snout", V(2, 0.8, 3.6), CFrame.new(0, 0.1, -7.2), GREEN, "Head")
	add("Jaw", V(1.9, 0.5, 5), CFrame.new(0, -0.45, -6.1), BELLY, "Head", V(0, -0.3, -3.7))

	local upZ = {-8.6, -7.5, -6.4}
	local lowZ = {-8.2, -7, -5.8}
	local ti = 0
	for i = 1, #upZ do
		for _, x in ipairs({-0.8, 0.8}) do
			ti = ti + 1
			add("TeethU" .. ti, V(0.25, 0.45, 0.25), CFrame.new(x, -0.5, upZ[i]), TOOTH, "Snout")
		end
	end
	for i = 1, #lowZ do
		for _, x in ipairs({-0.7, 0.7}) do
			ti = ti + 1
			add("TeethL" .. ti, V(0.25, 0.4, 0.25), CFrame.new(x, -0.05, lowZ[i]), TOOTH, "Jaw")
		end
	end

	for _, sd in ipairs(sides) do
		local n = sd[1]
		local s = sd[2]
		add("EyeBump" .. n, V(1, 0.9, 1), CFrame.new(1.0 * s, 1.0, -4.0), GREEN, "Head")
		add("Eye" .. n, V(0.5, 0.5, 0.6), CFrame.new(1.0 * s, 1.55, -4.3), EYEC, "Head")
		add("Pupil" .. n, V(0.15, 0.4, 0.2), CFrame.new(1.0 * s, 1.55, -4.65), BLACK, "Head")
		add("Nostril" .. n, V(0.4, 0.3, 0.4), CFrame.new(0.5 * s, 0.55, -8.9), DARK, "Snout")
	end

	-- Ekor
	add("Tail1", V(3, 1.3, 4), CFrame.new(0, 0.1, 5), GREEN, "Body", V(0, 0.1, 3))
	add("Tail2", V(2.2, 1, 4), CFrame.new(0, 0, 9), GREEN, "Tail1", V(0, 0.05, 7))
	add("Tail3", V(1.5, 0.8, 4), CFrame.new(0, -0.05, 13), GREEN, "Tail2", V(0, 0, 11))
	add("Tail4", V(0.9, 0.6, 3.5), CFrame.new(0, -0.1, 16.5), DARK, "Tail3", V(0, 0, 15))
	add("TailScute1", V(0.6, 0.5, 1), CFrame.new(0, 0.9, 5), DARK, "Tail1")
	add("TailScute2", V(0.5, 0.5, 1), CFrame.new(0, 0.75, 9), DARK, "Tail2")

	model.Parent = crocFolder
	return model, root, M, B
end

-- ============ HELPER ============
local function nearestTarget(pos, range)
	local bestHrp = nil
	local bestHum = nil
	local bestD = nil
	for _, plr in ipairs(Players:GetPlayers()) do
		local char = plr.Character
		local hum = char and char:FindFirstChildOfClass("Humanoid")
		local hrp = char and char:FindFirstChild("HumanoidRootPart")
		if hum and hrp and hum.Health > 0 then
			local dx = hrp.Position.X - pos.X
			local dz = hrp.Position.Z - pos.Z
			local dy = math.abs(hrp.Position.Y - pos.Y)
			local d = math.sqrt(dx * dx + dz * dz)
			if d <= range and dy <= VERTICAL_RANGE and (bestD == nil or d < bestD) then
				bestHrp = hrp
				bestHum = hum
				bestD = d
			end
		end
	end
	return bestHrp, bestHum, bestD
end

local function faceYaw(c, desired, rate, dt)
	local diff = wrapAngle(desired - c.yaw)
	local step = rate * dt
	if diff > step then
		diff = step
	elseif diff < -step then
		diff = -step
	end
	c.yaw = c.yaw + diff
end

local function checkHit(c)
	local fwd = V(-math.sin(c.yaw), 0, -math.cos(c.yaw))
	local head = c.pos + fwd * (6 * S)
	for _, plr in ipairs(Players:GetPlayers()) do
		local char = plr.Character
		local hum = char and char:FindFirstChildOfClass("Humanoid")
		local hrp = char and char:FindFirstChild("HumanoidRootPart")
		if hum and hrp and hum.Health > 0 and not c.hit[plr] then
			if (hrp.Position - head).Magnitude <= HIT_RADIUS then
				c.hit[plr] = true
				hum:TakeDamage(DAMAGE)
			end
		end
	end
end

local function startLeap(c, from, to, height, attack)
	if attack then
		c.state = "leap"
	else
		c.state = "return"
	end
	c.stateT = 0
	c.leapFrom = from
	c.leapTo = to
	c.leapH = height
	c.hit = {}
	local flat = V(to.X - from.X, 0, to.Z - from.Z)
	c.leapLen = math.max(1, flat.Magnitude)
	if flat.Magnitude > 0.1 then
		c.yaw = math.atan2(-flat.X, -flat.Z)
	end
end

-- ============ UPDATE SATU BUAYA ============
local function update(c, dt, now)
	local wp = c.water
	if wp == nil or wp.Parent == nil then
		return
	end
	local hx = math.max(0, wp.Size.X / 2 - EDGE_MARGIN)
	local hz = math.max(0, wp.Size.Z / 2 - EDGE_MARGIN)
	local swimAmt = 0
	local jawTarget = -0.03
	local dip = 0
	local pitch = 0
	local fast = 0

	if c.state == "swim" then
		local tHrp, tHum, tDist = nil, nil, nil
		if not DECORATION_ONLY then
			tHrp, tHum, tDist = nearestTarget(c.pos, DETECT_RANGE)
		end
		local speed = SWIM_SPEED
		local goal = nil
		if tHrp then
			local lp = wp.CFrame:PointToObjectSpace(tHrp.Position)
			goal = V(math.clamp(lp.X, -hx, hx), 0, math.clamp(lp.Z, -hz, hz))
			speed = STALK_SPEED
			jawTarget = -0.3
		else
			if c.wander == nil or now >= c.nextWander then
				c.wander = V((math.random() * 2 - 1) * hx, 0, (math.random() * 2 - 1) * hz)
				c.nextWander = now + rand(5, 10)
				if math.random() < 0.25 then
					c.idleUntil = now + rand(1, 3)
				end
			end
			goal = c.wander
		end

		local goalW = wp.CFrame:PointToWorldSpace(V(goal.X, wp.Size.Y / 2, goal.Z))
		local toX = goalW.X - c.pos.X
		local toZ = goalW.Z - c.pos.Z
		local dist = math.sqrt(toX * toX + toZ * toZ)
		if dist > 2 then
			if now >= c.idleUntil then
				local desired = math.atan2(-toX, -toZ)
				local align = math.cos(wrapAngle(desired - c.yaw))
				faceYaw(c, desired, TURN_SPEED, dt)
				local v = speed * math.max(0.25, align)
				local fwd = V(-math.sin(c.yaw), 0, -math.cos(c.yaw))
				c.pos = c.pos + fwd * v * dt
				swimAmt = math.clamp(v / STALK_SPEED, 0.25, 1)
			end
		else
			if tHrp == nil then
				c.nextWander = 0
			end
		end

		-- tetap di dalam air
		local lp2 = wp.CFrame:PointToObjectSpace(c.pos)
		c.pos = wp.CFrame:PointToWorldSpace(V(
			math.clamp(lp2.X, -hx, hx),
			wp.Size.Y / 2 + FLOAT * S,
			math.clamp(lp2.Z, -hz, hz)
		))

		-- mulai melompat
		if ENABLE_JUMP and not DECORATION_ONLY and tHrp and tDist <= JUMP_RANGE and now - c.lastJump >= JUMP_COOLDOWN then
			c.state = "windup"
			c.stateT = 0
			c.tHrp = tHrp
			c.homePos = c.pos
		end

	elseif c.state == "windup" then
		c.stateT = c.stateT + dt
		local hrp = c.tHrp
		if hrp == nil or hrp.Parent == nil then
			c.state = "swim"
			c.lastJump = now
		else
			local to = hrp.Position - c.pos
			faceYaw(c, math.atan2(-to.X, -to.Z), TURN_SPEED * 3, dt)
			jawTarget = -0.5
			dip = math.min(1, c.stateT / WINDUP_TIME)
			swimAmt = 0.3
			if c.stateT >= WINDUP_TIME then
				local pred = hrp.Position + hrp.AssemblyLinearVelocity * LEAP_TIME * 0.7
				local offX = pred.X - c.pos.X
				local offZ = pred.Z - c.pos.Z
				local len = math.sqrt(offX * offX + offZ * offZ)
				local maxD = JUMP_RANGE * 1.3
				if len > maxD then
					offX = offX / len * maxD
					offZ = offZ / len * maxD
				end
				local land = V(c.pos.X + offX, hrp.Position.Y - 1.5 + 0.5 * S, c.pos.Z + offZ)
				startLeap(c, c.pos, land, JUMP_HEIGHT, true)
			end
		end

	elseif c.state == "leap" or c.state == "return" then
		c.stateT = c.stateT + dt
		local u = math.min(1, c.stateT / LEAP_TIME)
		local h = c.leapH
		c.pos = c.leapFrom:Lerp(c.leapTo, u) + V(0, 4 * h * u * (1 - u), 0)
		local slope = (c.leapTo.Y - c.leapFrom.Y) + 4 * h * (1 - 2 * u)
		pitch = math.atan2(slope, c.leapLen)
		fast = 1
		swimAmt = 0.6

		if c.state == "leap" then
			if u < 0.7 then
				jawTarget = -1.0
			else
				jawTarget = 0
			end
			if u > 0.45 then
				checkHit(c)
			end
			if u >= 1 then
				c.state = "recover"
				c.stateT = 0
			end
		else
			jawTarget = -0.2
			if u >= 1 then
				c.state = "swim"
				c.pos = c.homePos
				c.lastJump = now
				c.wander = nil
				c.idleUntil = now + 1
			end
		end

	elseif c.state == "recover" then
		c.stateT = c.stateT + dt
		jawTarget = 0
		swimAmt = 0.5
		local to = c.homePos - c.pos
		faceYaw(c, math.atan2(-to.X, -to.Z), TURN_SPEED * 3, dt)
		if c.stateT >= RECOVER_TIME then
			startLeap(c, c.pos, c.homePos, JUMP_HEIGHT * 0.6, false)
		end
	end

	-- ============ ANIMASI ============
	c.sw = c.sw + (swimAmt - c.sw) * math.min(1, dt * 4)
	c.phase = c.phase + dt * (1.6 + c.sw * 3.4 + fast * 5)
	c.jaw = c.jaw + (jawTarget - c.jaw) * math.min(1, dt * 14)
	local ph = c.phase
	local sw = c.sw
	local M = c.M
	local B = c.B

	c.root.CFrame = CFrame.new(c.pos) * CFrame.Angles(0, c.yaw, 0) * CFrame.Angles(pitch, 0, math.sin(ph) * 0.04 * sw)

	M.Body.C0 = B.Body * CFrame.new(0, (math.sin(ph * 0.5) * 0.1 - dip * 0.5) * S, 0)
	M.Head.C0 = B.Head * CFrame.Angles(dip * 0.2, math.sin(ph - 2.5) * 0.1 * sw, 0)
	M.Jaw.C0 = B.Jaw * CFrame.Angles(c.jaw, 0, 0)

	for i = 1, 4 do
		local ang = math.sin(ph - i * 0.9) * (0.08 + 0.2 * sw) * (0.6 + 0.25 * i)
		M["Tail" .. i].C0 = B["Tail" .. i] * CFrame.Angles(0, ang, 0)
	end

	local legSides = {{"L", -1}, {"R", 1}}
	for _, sd in ipairs(legSides) do
		local n = sd[1]
		local s = sd[2]
		local angF = -s * (0.5 + math.sin(ph * 2) * 0.35 * sw)
		local angB = -s * (0.5 + math.sin(ph * 2 + math.pi) * 0.35 * sw)
		M["LegF" .. n].C0 = B["LegF" .. n] * CFrame.Angles(0, angF, 0)
		M["LegB" .. n].C0 = B["LegB" .. n] * CFrame.Angles(0, angB, 0)
	end
end

-- ============ MEMBUAT SEMUA BUAYA ============
local crocs = {}
for i = 1, CROC_COUNT do
	local wp = pickWater()
	local hx = math.max(0, wp.Size.X / 2 - EDGE_MARGIN)
	local hz = math.max(0, wp.Size.Z / 2 - EDGE_MARGIN)
	local pos = wp.CFrame:PointToWorldSpace(V(
		(math.random() * 2 - 1) * hx,
		wp.Size.Y / 2 + FLOAT * S,
		(math.random() * 2 - 1) * hz
	))
	local yaw = rand(0, math.pi * 2)
	local model, root, M, B = buildCroc(CFrame.new(pos) * CFrame.Angles(0, yaw, 0))
	table.insert(crocs, {
		water = wp,
		model = model,
		root = root,
		M = M,
		B = B,
		pos = pos,
		yaw = yaw,
		state = "swim",
		stateT = 0,
		lastJump = -100,
		idleUntil = 0,
		nextWander = 0,
		wander = nil,
		phase = rand(0, 6),
		sw = 0,
		jaw = 0,
		hit = {},
	})
end
print("[Buaya] " .. #crocs .. " buaya dibuat.")

RunService.Heartbeat:Connect(function(dt)
	local now = os.clock()
	for _, c in ipairs(crocs) do
		update(c, dt, now)
	end
end)
ScriptVersi 2
-- CrocodileSpawner (Script, BUKAN LocalScript) -> ServerScriptService
local Players, RunService = game:GetService("Players"), game:GetService("RunService")
local CROC_COUNT, CROC_SCALE = 5, 1.6
local WATER_FOLDER_NAME, WATER_PART_NAME = "Water", "water" -- folder "" = cari otomatis
local SWIM_SPEED, STALK_SPEED, TURN_SPEED, EDGE_MARGIN = 7, 16, 2, 6
local DECORATION_ONLY = true -- true = hiasan, false = menyerang
local IDLE_JAW = -0.55
local DETECT_RANGE, ENABLE_JUMP, JUMP_RANGE, JUMP_HEIGHT = 90, true, 60, 18
local LEAP_TIME, WINDUP_TIME, RECOVER_TIME, JUMP_COOLDOWN = 1, 0.5, 0.6, 5
local DAMAGE, HIT_RADIUS = 30, 16
local STUDS_ALL_SIDES = true
local C = Color3.fromRGB
local GREEN, LIGHT, DARK = C(60,170,50), C(100,205,65), C(35,120,40)
local BELLY, TOOTH, RED, DRED = C(215,185,130), C(245,235,215), C(200,30,30), C(130,15,20)
local EYEC, BLACK = C(255,215,40), C(15,15,15)

local S, V, FLOAT, VRANGE = CROC_SCALE, Vector3.new, 0.3, 40
local SURFACES = {"TopSurface","BottomSurface","LeftSurface","RightSurface","FrontSurface","BackSurface"}
local SIDES = {{"L", -1}, {"R", 1}}
local function rand(a, b) return a + math.random() * (b - a) end
local function wrapAngle(a) return (a + math.pi) % (2 * math.pi) - math.pi end
local function fwdOf(yaw) return V(-math.sin(yaw), 0, -math.cos(yaw)) end
-- batas jelajah di dalam part air (margin menyesuaikan ukuran part)
local function lim(wp)
    return math.max(0, wp.Size.X/2 - math.min(EDGE_MARGIN, wp.Size.X*0.15)),
        math.max(0, wp.Size.Z/2 - math.min(EDGE_MARGIN, wp.Size.Z*0.15))
end

local function findFolder()
    if WATER_FOLDER_NAME ~= "" then return workspace:FindFirstChild(WATER_FOLDER_NAME, true) end
    for _, c in ipairs(workspace:GetChildren()) do
        if (c:IsA("Folder") or c:IsA("Model")) and string.find(string.lower(c.Name), "water") then return c end end
end
task.wait(1)
local waters, totalArea = {}, 0
for _, d in ipairs((findFolder() or workspace):GetDescendants()) do
    if d:IsA("BasePart") and string.lower(d.Name) == string.lower(WATER_PART_NAME) then
        table.insert(waters, d)
        totalArea = totalArea + d.Size.X * d.Size.Z
    end
end
if #waters == 0 then warn("[Buaya] Part air tidak ditemukan.") return end
local function pickWater()
    local r = math.random() * totalArea
    for _, w in ipairs(waters) do
        r = r - w.Size.X * w.Size.Z
        if r <= 0 then return w end end
    return waters[#waters]
end
local crocFolder = Instance.new("Folder")
crocFolder.Name = "Crocodiles"
crocFolder.Parent = workspace

local function sc(cf) return CFrame.new(cf.Position * S) * (cf - cf.Position) end

local function buildCroc(spawnCF)
    local model = Instance.new("Model")
    model.Name = "Crocodile"
    local root = Instance.new("Part")
    root.Name, root.Size, root.Transparency, root.Anchored = "Root", V(1,1,1) * S, 1, true
    root.CanCollide, root.CanTouch, root.CanQuery = false, false, false
    root.CFrame, root.Parent, model.PrimaryPart = spawnCF, model, root
    local parts, rels, M, B = {Root = root}, {Root = CFrame.new()}, {}, {}

    local function add(name, size, cf, color, parent, joint, neon)
        local rel = sc(cf)
        local p = Instance.new("Part")
        p.Name, p.Size, p.Color = name, size * S, color
        p.Material = neon and Enum.Material.Neon or Enum.Material.Plastic
        p.CanCollide, p.CanTouch, p.CanQuery, p.Massless = false, false, false, true
        p.CFrame = spawnCF * rel
        for _, s in ipairs(SURFACES) do
            p[s] = (STUDS_ALL_SIDES or s == "TopSurface") and Enum.SurfaceType.Studs or Enum.SurfaceType.Smooth
        end
        local jcf = CFrame.new((joint or cf.Position) * S)
        local m = Instance.new("Motor6D")
        m.Name, m.Part0, m.Part1 = name, parts[parent], p
        m.C0, m.C1 = rels[parent]:Inverse() * jcf, rel:Inverse() * jcf
        m.Parent, p.Parent = p, model
        parts[name], rels[name], M[name], B[name] = p, rel, m, m.C0
        return p
    end

    add("Body", V(5,2.2,7), CFrame.new(0,0.2,0), GREEN, "Root", V(0,0,0))
    add("Belly", V(4.2,0.5,6.4), CFrame.new(0,-0.95,0), BELLY, "Body")
    add("BodyTop", V(4.2,0.6,6.2), CFrame.new(0,1.5,0), LIGHT, "Body")
    for i, z in ipairs({-2.4,-0.8,0.8,2.4}) do
        add("ScuteL"..i, V(1,0.6,1), CFrame.new(-1.3,2,z), DARK, "Body")
        add("ScuteR"..i, V(1,0.6,1), CFrame.new(1.3,2,z), DARK, "Body")
    end
    for i, z in ipairs({-1.6,0,1.6}) do add("ScuteM"..i, V(1,0.7,1), CFrame.new(0,2.05,z), DARK, "Body") end

    local function addLeg(tag, n, s, zc, k, toes)
        local up, fore, foot = "Leg"..tag..n, "Fore"..tag..n, "Foot"..tag..n
        add("Haunch"..tag..n, V(1.7*k,1.4*k,2*k), CFrame.new(2.7*s,-0.05,zc), GREEN, "Body")
        add(up, V(2.1,1*k,1.3*k), CFrame.new(3.38*s,-0.29,zc) * CFrame.Angles(0,0,-s*0.38), DARK, "Body", V(2.4*s,0.1,zc))
        add(fore, V(0.85*k,0.85,0.85*k), CFrame.new(4.2*s,-0.92,zc) * CFrame.Angles(0,0,-s*0.15), GREEN, up, V(4.35*s,-0.62,zc))
        local fz = zc - 0.2
        add(foot, V(1.3*k,0.3,1.3*k), CFrame.new(4.15*s,-1.25,fz), GREEN, fore, V(4.1*s,-1.12,zc))
        for i = 1, toes do
            local a = i - (toes + 1) / 2
            local base = V(4.15*s + s*a*0.27*k, -1.28, fz - 0.65*k)
            local rot = CFrame.new(base) * CFrame.Angles(0, -s*a*0.28, 0)
            local tn = "Toe"..tag..n..i
            add(tn, V(0.3*k,0.25,1*k), rot * CFrame.new(0,0,-0.5*k), DARK, foot, base)
            add("Claw"..tag..n..i, V(0.22,0.2,0.45), rot * CFrame.new(0,-0.03,-1.1*k), TOOTH, tn)
        end
    end
    for _, sd in ipairs(SIDES) do
        addLeg("F", sd[1], sd[2], -2.4, 0.9, 5)
        addLeg("B", sd[1], sd[2], 3, 1.1, 4)
    end

    add("Head", V(4,1.6,3.6), CFrame.new(0,0.5,-5.2), GREEN, "Body", V(0,0.5,-3.5))
    add("HeadTop", V(3.4,0.5,3), CFrame.new(0,1.5,-5.2), LIGHT, "Head")
    add("Snout", V(3,1.1,4.6), CFrame.new(0,0.75,-9.3), GREEN, "Head")
    add("SnoutTop", V(2.6,0.4,4.2), CFrame.new(0,1.5,-9.3), LIGHT, "Snout")
    add("MouthRoof", V(2.6,0.25,4.2), CFrame.new(0,0.05,-9.1), RED, "Snout")
    add("Throat", V(3.2,1,0.4), CFrame.new(0,0.1,-6.9), DRED, "Head")
    add("Jaw", V(3.2,0.8,6.4), CFrame.new(0,-0.6,-9.2), BELLY, "Head", V(0,-0.2,-6.2))
    add("Tongue", V(2,0.3,4.6), CFrame.new(0,-0.1,-9), RED, "Jaw")

    local ti = 0
    for _, z in ipairs({-8,-9.1,-10.2,-11.3}) do
        for _, x in ipairs({-1.3,1.3}) do ti = ti + 1 add("TeethU"..ti, V(0.45,1,0.45), CFrame.new(x,-0.3,z), TOOTH, "Snout") end
    end
    add("FangU", V(0.5,1.2,0.5), CFrame.new(0,-0.4,-11.5), TOOTH, "Snout")
    for _, z in ipairs({-7.2,-8.4,-9.6,-10.8,-12}) do
        for _, x in ipairs({-1.3,1.3}) do ti = ti + 1 add("TeethL"..ti, V(0.4,0.9,0.4), CFrame.new(x,0.25,z), TOOTH, "Jaw") end
    end

    for _, sd in ipairs(SIDES) do
        local n, s = sd[1], sd[2]
        add("EyeBump"..n, V(1.2,1,1.2), CFrame.new(1.5*s,1.5,-5.6), GREEN, "Head")
        add("Eye"..n, V(0.8,0.7,0.8), CFrame.new(1.5*s,2.2,-5.6), EYEC, "Head", nil, true)
        add("Pupil"..n, V(0.2,0.5,0.2), CFrame.new(1.5*s,2.35,-6), BLACK, "Head")
        add("Nostril"..n, V(0.5,0.4,0.5), CFrame.new(0.7*s,1.55,-11.3), DARK, "Snout")
    end

    local tails = {{V(4,1.8,4.5), 5.5, 0.2, 3.5, GREEN}, {V(3.2,1.5,4.5), 10, 0.1, 8, GREEN},
        {V(2.4,1.2,4.5), 14.5, 0, 12.5, GREEN}, {V(1.6,0.9,4.5), 19, -0.1, 17, DARK}, {V(0.9,0.6,4), 23.2, -0.15, 21, DARK}}
    for i, t in ipairs(tails) do
        add("Tail"..i, t[1], CFrame.new(0,t[3],t[2]), t[5], i > 1 and "Tail"..(i-1) or "Body", V(0,t[3],t[4]))
        if i <= 4 then add("TailScute"..i, V(0.8,0.6,1.2), CFrame.new(0,t[3]+t[1].Y/2+0.3,t[2]), DARK, "Tail"..i) end
    end
    model.Parent = crocFolder
    return model, root, M, B
end

local function charParts(plr)
    local ch = plr.Character
    local hum = ch and ch:FindFirstChildOfClass("Humanoid")
    local hrp = ch and ch:FindFirstChild("HumanoidRootPart")
    if hum and hrp and hum.Health > 0 then return hum, hrp end
end

local function nearestTarget(pos, range)
    local bh, bd
    for _, plr in ipairs(Players:GetPlayers()) do
        local hum, hrp = charParts(plr)
        if hrp then
            local d = math.sqrt((hrp.Position.X-pos.X)^2 + (hrp.Position.Z-pos.Z)^2)
            if d <= range and math.abs(hrp.Position.Y-pos.Y) <= VRANGE and (not bd or d < bd) then bh, bd = hrp, d end
        end
    end
    return bh, bd
end

local function faceYaw(c, desired, rate, dt)
    local step = rate * dt
    c.yaw = c.yaw + math.clamp(wrapAngle(desired - c.yaw), -step, step)
end

local function checkHit(c)
    local head = c.pos + fwdOf(c.yaw) * (10 * S)
    for _, plr in ipairs(Players:GetPlayers()) do
        local hum, hrp = charParts(plr)
        if hum and not c.hit[plr] and (hrp.Position - head).Magnitude <= HIT_RADIUS then c.hit[plr] = true hum:TakeDamage(DAMAGE) end
    end
end

local function startLeap(c, from, to, height, attack)
    c.state, c.stateT, c.leapFrom, c.leapTo, c.leapH, c.hit = attack and "leap" or "return", 0, from, to, height, {}
    local flat = V(to.X-from.X, 0, to.Z-from.Z)
    c.leapLen = math.max(1, flat.Magnitude)
    if flat.Magnitude > 0.1 then c.yaw = math.atan2(-flat.X, -flat.Z) end
end

local function update(c, dt, now)
    local wp = c.water
    if not wp or not wp.Parent then return end
    local hx, hz = lim(wp)
    local swimAmt, dip, pitch, fast = 0, 0, 0, 0
    local jawT = IDLE_JAW + math.sin(c.phase * 0.7) * 0.06
    local st = c.state

    if st == "swim" then
        local tHrp, tDist
        if not DECORATION_ONLY then tHrp, tDist = nearestTarget(c.pos, DETECT_RANGE) end
        local speed, goal = SWIM_SPEED, nil
        if tHrp then
            local lp = wp.CFrame:PointToObjectSpace(tHrp.Position)
            goal, speed, jawT = V(math.clamp(lp.X,-hx,hx), 0, math.clamp(lp.Z,-hz,hz)), STALK_SPEED, -0.9
        else
            if not c.wander or now >= c.nextWander then
                c.wander = V((math.random()*2-1)*hx, 0, (math.random()*2-1)*hz)
                c.nextWander = now + rand(6, 12)
                if math.random() < 0.25 then c.idleUntil = now + rand(1, 3) end
            end
            goal = c.wander
        end
        local gw = wp.CFrame:PointToWorldSpace(V(goal.X, wp.Size.Y/2, goal.Z))
        local toX, toZ = gw.X - c.pos.X, gw.Z - c.pos.Z
        if math.sqrt(toX*toX + toZ*toZ) > 2 then
            if now >= c.idleUntil then
                local desired = math.atan2(-toX, -toZ)
                faceYaw(c, desired, TURN_SPEED, dt)
                local v = speed * math.max(0.25, math.cos(wrapAngle(desired - c.yaw)))
                c.pos = c.pos + fwdOf(c.yaw) * v * dt
                swimAmt = math.clamp(v / STALK_SPEED, 0.25, 1)
            end
        elseif not tHrp then
            c.nextWander = 0
        end
        local lp2 = wp.CFrame:PointToObjectSpace(c.pos)
        c.pos = wp.CFrame:PointToWorldSpace(V(math.clamp(lp2.X,-hx,hx), wp.Size.Y/2 + FLOAT*S, math.clamp(lp2.Z,-hz,hz)))
        if ENABLE_JUMP and not DECORATION_ONLY and tHrp and tDist <= JUMP_RANGE and now - c.lastJump >= JUMP_COOLDOWN then
            c.state, c.stateT, c.tHrp, c.homePos = "windup", 0, tHrp, c.pos
        end

    elseif st == "windup" then
        c.stateT = c.stateT + dt
        local hrp = c.tHrp
        if not hrp or not hrp.Parent then
            c.state, c.lastJump = "swim", now
        else
            local to = hrp.Position - c.pos
            faceYaw(c, math.atan2(-to.X, -to.Z), TURN_SPEED * 3, dt)
            jawT, dip, swimAmt = -0.8, math.min(1, c.stateT / WINDUP_TIME), 0.3
            if c.stateT >= WINDUP_TIME then
                local pred = hrp.Position + hrp.AssemblyLinearVelocity * LEAP_TIME * 0.7
                local offX, offZ = pred.X - c.pos.X, pred.Z - c.pos.Z
                local len, maxD = math.sqrt(offX*offX + offZ*offZ), JUMP_RANGE * 1.3
                if len > maxD then offX, offZ = offX/len*maxD, offZ/len*maxD end
                startLeap(c, c.pos, V(c.pos.X+offX, hrp.Position.Y - 1.5 + 0.5*S, c.pos.Z+offZ), JUMP_HEIGHT, true)
            end
        end

    elseif st == "leap" or st == "return" then
        c.stateT = c.stateT + dt
        local u, h = math.min(1, c.stateT / LEAP_TIME), c.leapH
        c.pos = c.leapFrom:Lerp(c.leapTo, u) + V(0, 4*h*u*(1-u), 0)
        pitch = math.atan2((c.leapTo.Y - c.leapFrom.Y) + 4*h*(1-2*u), c.leapLen)
        fast, swimAmt = 1, 0.6
        if st == "leap" then
            jawT = (u < 0.7) and -1.1 or -0.1
            if u > 0.45 then checkHit(c) end
            if u >= 1 then c.state, c.stateT = "recover", 0 end
        else
            jawT = -0.3
            if u >= 1 then
                c.state, c.pos, c.lastJump, c.wander, c.idleUntil = "swim", c.homePos, now, nil, now + 1
            end
        end

    elseif st == "recover" then
        c.stateT = c.stateT + dt
        jawT, swimAmt = -0.1, 0.5
        local to = c.homePos - c.pos
        faceYaw(c, math.atan2(-to.X, -to.Z), TURN_SPEED * 3, dt)
        if c.stateT >= RECOVER_TIME then startLeap(c, c.pos, c.homePos, JUMP_HEIGHT * 0.6, false) end
    end

    c.sw = c.sw + (swimAmt - c.sw) * math.min(1, dt * 4)
    c.phase = c.phase + dt * (1.6 + c.sw * 3.4 + fast * 5)
    c.jaw = c.jaw + (jawT - c.jaw) * math.min(1, dt * 14)
    local ph, sw, M, B = c.phase, c.sw, c.M, c.B
    c.root.CFrame = CFrame.new(c.pos) * CFrame.Angles(0, c.yaw, 0) * CFrame.Angles(pitch, 0, math.sin(ph) * 0.04 * sw)
    M.Body.C0 = B.Body * CFrame.new(0, (math.sin(ph*0.5)*0.1 - dip*0.5) * S, 0)
    M.Head.C0 = B.Head * CFrame.Angles(dip*0.2, math.sin(ph-2.5)*0.1*sw, 0)
    M.Jaw.C0 = B.Jaw * CFrame.Angles(c.jaw, 0, 0)
    for i = 1, 5 do
        M["Tail"..i].C0 = B["Tail"..i] * CFrame.Angles(0, math.sin(ph - i*0.9) * (0.08 + 0.2*sw) * (0.6 + 0.25*i), 0)
    end
    for _, sd in ipairs(SIDES) do
        local n, s = sd[1], sd[2]
        for _, t in ipairs({{"F", 0}, {"B", math.pi}}) do
            local tag, off = t[1], t[2]
            local lift = math.max(0, -math.cos(ph*2 + off)) * 0.6 * sw
            M["Leg"..tag..n].C0 = B["Leg"..tag..n] * CFrame.Angles(0, -s*(0.5 + math.sin(ph*2+off)*0.35*sw), 0)
            M["Fore"..tag..n].C0 = B["Fore"..tag..n] * CFrame.Angles(lift, 0, 0)
            M["Foot"..tag..n].C0 = B["Foot"..tag..n] * CFrame.Angles(-lift*0.5, 0, 0)
        end
    end
end

local crocs = {}
for i = 1, CROC_COUNT do
    local wp = pickWater()
    local hx, hz = lim(wp)
    local pos = wp.CFrame:PointToWorldSpace(V((math.random()*2-1)*hx, wp.Size.Y/2 + FLOAT*S, (math.random()*2-1)*hz))
    local yaw = rand(0, math.pi * 2)
    local model, root, M, B = buildCroc(CFrame.new(pos) * CFrame.Angles(0, yaw, 0))
    table.insert(crocs, {water = wp, model = model, root = root, M = M, B = B, pos = pos, yaw = yaw,
        state = "swim", stateT = 0, lastJump = -100, idleUntil = 0, nextWander = 0,
        phase = rand(0, 6), sw = 0, jaw = IDLE_JAW, hit = {}})
end
print("[Buaya] " .. #crocs .. " buaya dibuat.")
RunService.Heartbeat:Connect(function(dt)
    local now = os.clock()
    for _, c in ipairs(crocs) do update(c, dt, now) end
end)
ScriptVersi 3
-- CrocodileSpawner (Script, BUKAN LocalScript) -> ServerScriptService
local Players, RunService = game:GetService("Players"), game:GetService("RunService")
local CROC_COUNT, CROC_SCALE = 5, 1.1
local WATER_PART_NAME = "BuayaPlace" -- semua part dengan nama ini dipakai
local SWIM_SPEED, STALK_SPEED, TURN_SPEED, EDGE_MARGIN = 6, 14, 2, 3
local DECORATION_ONLY = true -- true = hiasan, false = menyerang
local IDLE_JAW = -0.55
local DETECT_RANGE, ENABLE_JUMP, JUMP_RANGE, JUMP_HEIGHT = 90, true, 60, 18
local LEAP_TIME, WINDUP_TIME, RECOVER_TIME, JUMP_COOLDOWN = 1, 0.5, 0.6, 5
local DAMAGE, HIT_RADIUS = 30, 16
local STUDS_ALL_SIDES = true
local C = Color3.fromRGB
local GREEN, LIGHT, DARK = C(60,170,50), C(100,205,65), C(35,120,40)
local BELLY, TOOTH, RED, DRED = C(215,185,130), C(245,235,215), C(200,30,30), C(130,15,20)
local EYEC, BLACK = C(255,215,40), C(15,15,15)

local S, V, FLOAT, VRANGE = CROC_SCALE, Vector3.new, 1.4, 40 -- FLOAT: tinggi badan (kaki menapak)
local SURFACES = {"TopSurface","BottomSurface","LeftSurface","RightSurface","FrontSurface","BackSurface"}
local SIDES = {{"L", -1}, {"R", 1}}
local function rand(a, b) return a + math.random() * (b - a) end
local function wrapAngle(a) return (a + math.pi) % (2 * math.pi) - math.pi end
local function fwdOf(yaw) return V(-math.sin(yaw), 0, -math.cos(yaw)) end

-- batas jelajah di dalam part air (margin menyesuaikan ukuran part)
local function lim(wp)
    return math.max(0, wp.Size.X/2 - math.min(EDGE_MARGIN, wp.Size.X*0.15)),
    math.max(0, wp.Size.Z/2 - math.min(EDGE_MARGIN, wp.Size.Z*0.15))
end

task.wait(1)
local waters, totalArea = {}, 0
for _, d in ipairs(workspace:GetDescendants()) do
    if d:IsA("BasePart") and string.lower(d.Name) == string.lower(WATER_PART_NAME) then
        table.insert(waters, d)
        totalArea = totalArea + d.Size.X * d.Size.Z
    end
end
if #waters == 0 then warn("[Buaya] Part Water tidak ditemukan.") return end
local function pickWater()
    local r = math.random() * totalArea
    for _, w in ipairs(waters) do
        r = r - w.Size.X * w.Size.Z
        if r <= 0 then return w end end
        return waters[#waters]
    end
    local crocFolder = Instance.new("Folder")
    crocFolder.Name = "Crocodiles"
    crocFolder.Parent = workspace
    
    local function sc(cf) return CFrame.new(cf.Position * S) * (cf - cf.Position) end
    
    local function buildCroc(spawnCF)
        local model = Instance.new("Model")
        model.Name = "Crocodile"
        local root = Instance.new("Part")
        root.Name, root.Size, root.Transparency, root.Anchored = "Root", V(1,1,1) * S, 1, true
        root.CanCollide, root.CanTouch, root.CanQuery = false, false, false
        root.CFrame, root.Parent, model.PrimaryPart = spawnCF, model, root
        local parts, rels, M, B = {Root = root}, {Root = CFrame.new()}, {}, {}
        
        local function add(name, size, cf, color, parent, joint, neon)
            local rel = sc(cf)
            local p = Instance.new("Part")
            p.Name, p.Size, p.Color = name, size * S, color
            p.Material = neon and Enum.Material.Neon or Enum.Material.Plastic
            p.CanCollide, p.CanTouch, p.CanQuery, p.Massless = false, false, false, true
            p.CFrame = spawnCF * rel
            for _, s in ipairs(SURFACES) do
                p[s] = (STUDS_ALL_SIDES or s == "TopSurface") and Enum.SurfaceType.Studs or Enum.SurfaceType.Smooth
            end
            local jcf = CFrame.new((joint or cf.Position) * S)
            local m = Instance.new("Motor6D")
            m.Name, m.Part0, m.Part1 = name, parts[parent], p
            m.C0, m.C1 = rels[parent]:Inverse() * jcf, rel:Inverse() * jcf
            m.Parent, p.Parent = p, model
            parts[name], rels[name], M[name], B[name] = p, rel, m, m.C0
            return p
        end
        
        add("Body", V(5,2.2,7), CFrame.new(0,0.2,0), GREEN, "Root", V(0,0,0))
        add("Belly", V(4.2,0.5,6.4), CFrame.new(0,-0.95,0), BELLY, "Body")
        add("BodyTop", V(4.2,0.6,6.2), CFrame.new(0,1.5,0), LIGHT, "Body")
        for i, z in ipairs({-2.4,-0.8,0.8,2.4}) do
            add("ScuteL"..i, V(1,0.6,1), CFrame.new(-1.3,2,z), DARK, "Body")
            add("ScuteR"..i, V(1,0.6,1), CFrame.new(1.3,2,z), DARK, "Body")
        end
        for i, z in ipairs({-1.6,0,1.6}) do add("ScuteM"..i, V(1,0.7,1), CFrame.new(0,2.05,z), DARK, "Body") end
        
        local function addLeg(tag, n, s, zc, k, toes)
            local up, fore, foot = "Leg"..tag..n, "Fore"..tag..n, "Foot"..tag..n
            add("Haunch"..tag..n, V(1.7*k,1.4*k,2*k), CFrame.new(2.7*s,-0.05,zc), GREEN, "Body")
            add(up, V(2.1,1*k,1.3*k), CFrame.new(3.38*s,-0.29,zc) * CFrame.Angles(0,0,-s*0.38), DARK, "Body", V(2.4*s,0.1,zc))
            add(fore, V(0.85*k,0.85,0.85*k), CFrame.new(4.2*s,-0.92,zc) * CFrame.Angles(0,0,-s*0.15), GREEN, up, V(4.35*s,-0.62,zc))
            local fz = zc - 0.2
            add(foot, V(1.3*k,0.3,1.3*k), CFrame.new(4.15*s,-1.25,fz), GREEN, fore, V(4.1*s,-1.12,zc))
            for i = 1, toes do
                local a = i - (toes + 1) / 2
                local base = V(4.15*s + s*a*0.27*k, -1.28, fz - 0.65*k)
                local rot = CFrame.new(base) * CFrame.Angles(0, -s*a*0.28, 0)
                local tn = "Toe"..tag..n..i
                add(tn, V(0.3*k,0.25,1*k), rot * CFrame.new(0,0,-0.5*k), DARK, foot, base)
                add("Claw"..tag..n..i, V(0.22,0.2,0.45), rot * CFrame.new(0,-0.03,-1.1*k), TOOTH, tn)
            end
        end
        for _, sd in ipairs(SIDES) do
            addLeg("F", sd[1], sd[2], -2.4, 0.9, 5)
            addLeg("B", sd[1], sd[2], 3, 1.1, 4)
        end
        
        add("Head", V(4,1.6,3.6), CFrame.new(0,0.5,-5.2), GREEN, "Body", V(0,0.5,-3.5))
        add("HeadTop", V(3.4,0.5,3), CFrame.new(0,1.5,-5.2), LIGHT, "Head")
        add("Snout", V(3,1.1,4.6), CFrame.new(0,0.75,-9.3), GREEN, "Head")
        add("SnoutTop", V(2.6,0.4,4.2), CFrame.new(0,1.5,-9.3), LIGHT, "Snout")
        add("MouthRoof", V(2.6,0.25,4.2), CFrame.new(0,0.05,-9.1), RED, "Snout")
        add("Throat", V(3.2,1,0.4), CFrame.new(0,0.1,-6.9), DRED, "Head")
        add("Jaw", V(3.2,0.8,6.4), CFrame.new(0,-0.6,-9.2), BELLY, "Head", V(0,-0.2,-6.2))
        add("Tongue", V(2,0.3,4.6), CFrame.new(0,-0.1,-9), RED, "Jaw")
        
        local ti = 0
        for _, z in ipairs({-8,-9.1,-10.2,-11.3}) do
            for _, x in ipairs({-1.3,1.3}) do ti = ti + 1 add("TeethU"..ti, V(0.45,1,0.45), CFrame.new(x,-0.3,z), TOOTH, "Snout") end
        end
        add("FangU", V(0.5,1.2,0.5), CFrame.new(0,-0.4,-11.5), TOOTH, "Snout")
        for _, z in ipairs({-7.2,-8.4,-9.6,-10.8,-12}) do
            for _, x in ipairs({-1.3,1.3}) do ti = ti + 1 add("TeethL"..ti, V(0.4,0.9,0.4), CFrame.new(x,0.25,z), TOOTH, "Jaw") end
        end
        
        for _, sd in ipairs(SIDES) do
            local n, s = sd[1], sd[2]
            add("EyeBump"..n, V(1.2,1,1.2), CFrame.new(1.5*s,1.5,-5.6), GREEN, "Head")
            add("Eye"..n, V(0.8,0.7,0.8), CFrame.new(1.5*s,2.2,-5.6), EYEC, "Head", nil, true)
            add("Pupil"..n, V(0.2,0.5,0.2), CFrame.new(1.5*s,2.35,-6), BLACK, "Head")
            add("Nostril"..n, V(0.5,0.4,0.5), CFrame.new(0.7*s,1.55,-11.3), DARK, "Snout")
        end
        
        local tails = {{V(4,1.8,4.5), 5.5, 0.2, 3.5, GREEN}, {V(3.2,1.5,4.5), 10, 0.1, 8, GREEN},
        {V(2.4,1.2,4.5), 14.5, 0, 12.5, GREEN}, {V(1.6,0.9,4.5), 19, -0.1, 17, DARK}, {V(0.9,0.6,4), 23.2, -0.15, 21, DARK}}
        for i, t in ipairs(tails) do
            add("Tail"..i, t[1], CFrame.new(0,t[3],t[2]), t[5], i > 1 and "Tail"..(i-1) or "Body", V(0,t[3],t[4]))
            if i <= 4 then add("TailScute"..i, V(0.8,0.6,1.2), CFrame.new(0,t[3]+t[1].Y/2+0.3,t[2]), DARK, "Tail"..i) end
        end
        model.Parent = crocFolder
        return model, root, M, B
    end
    
    local function charParts(plr)
        local ch = plr.Character
        local hum = ch and ch:FindFirstChildOfClass("Humanoid")
        local hrp = ch and ch:FindFirstChild("HumanoidRootPart")
        if hum and hrp and hum.Health > 0 then return hum, hrp end
    end
    
    local function nearestTarget(pos, range)
        local bh, bd
        for _, plr in ipairs(Players:GetPlayers()) do
            local hum, hrp = charParts(plr)
            if hrp then
                local d = math.sqrt((hrp.Position.X-pos.X)^2 + (hrp.Position.Z-pos.Z)^2)
                if d <= range and math.abs(hrp.Position.Y-pos.Y) <= VRANGE and (not bd or d < bd) then bh, bd = hrp, d end
            end
        end
        return bh, bd
    end
    
    local function faceYaw(c, desired, rate, dt)
        local step = rate * dt
        c.yaw = c.yaw + math.clamp(wrapAngle(desired - c.yaw), -step, step)
    end
    
    local function checkHit(c)
        local head = c.pos + fwdOf(c.yaw) * (10 * S)
        for _, plr in ipairs(Players:GetPlayers()) do
            local hum, hrp = charParts(plr)
            if hum and not c.hit[plr] and (hrp.Position - head).Magnitude <= HIT_RADIUS then c.hit[plr] = true hum:TakeDamage(DAMAGE) end
        end
    end
    
    local function startLeap(c, from, to, height, attack)
        c.state, c.stateT, c.leapFrom, c.leapTo, c.leapH, c.hit = attack and "leap" or "return", 0, from, to, height, {}
        local flat = V(to.X-from.X, 0, to.Z-from.Z)
        c.leapLen = math.max(1, flat.Magnitude)
        if flat.Magnitude > 0.1 then c.yaw = math.atan2(-flat.X, -flat.Z) end
    end
    
    local function update(c, dt, now)
        local wp = c.water
        if not wp or not wp.Parent then return end
        local hx, hz = lim(wp)
        local swimAmt, dip, pitch, fast = 0, 0, 0, 0
        local jawT = IDLE_JAW + math.sin(c.phase * 0.7) * 0.06
        local st = c.state
        
        if st == "swim" then
            local tHrp, tDist
            if not DECORATION_ONLY then tHrp, tDist = nearestTarget(c.pos, DETECT_RANGE) end
            local speed, goal = SWIM_SPEED, nil
            if tHrp then
                local lp = wp.CFrame:PointToObjectSpace(tHrp.Position)
                goal, speed, jawT = V(math.clamp(lp.X,-hx,hx), 0, math.clamp(lp.Z,-hz,hz)), STALK_SPEED, -0.9
            else
                if not c.wander or now >= c.nextWander then
                    c.wander = V((math.random()*2-1)*hx, 0, (math.random()*2-1)*hz)
                    c.nextWander = now + rand(6, 12)
                    if math.random() < 0.25 then c.idleUntil = now + rand(1, 3) end
                end
                goal = c.wander
            end
            local gw = wp.CFrame:PointToWorldSpace(V(goal.X, wp.Size.Y/2, goal.Z))
            local toX, toZ = gw.X - c.pos.X, gw.Z - c.pos.Z
            if math.sqrt(toX*toX + toZ*toZ) > 2 then
                if now >= c.idleUntil then
                    local desired = math.atan2(-toX, -toZ)
                    faceYaw(c, desired, TURN_SPEED, dt)
                    local v = speed * math.max(0.25, math.cos(wrapAngle(desired - c.yaw)))
                    c.pos = c.pos + fwdOf(c.yaw) * v * dt
                    swimAmt = math.clamp(v / STALK_SPEED, 0.25, 1)
                end
            elseif not tHrp then
                c.nextWander = 0
            end
            local lp2 = wp.CFrame:PointToObjectSpace(c.pos)
            c.pos = wp.CFrame:PointToWorldSpace(V(math.clamp(lp2.X,-hx,hx), wp.Size.Y/2 + FLOAT*S, math.clamp(lp2.Z,-hz,hz)))
            if ENABLE_JUMP and not DECORATION_ONLY and tHrp and tDist <= JUMP_RANGE and now - c.lastJump >= JUMP_COOLDOWN then
                c.state, c.stateT, c.tHrp, c.homePos = "windup", 0, tHrp, c.pos
            end
            
        elseif st == "windup" then
            c.stateT = c.stateT + dt
            local hrp = c.tHrp
            if not hrp or not hrp.Parent then
                c.state, c.lastJump = "swim", now
            else
                local to = hrp.Position - c.pos
                faceYaw(c, math.atan2(-to.X, -to.Z), TURN_SPEED * 3, dt)
                jawT, dip, swimAmt = -0.8, math.min(1, c.stateT / WINDUP_TIME), 0.3
                if c.stateT >= WINDUP_TIME then
                    local pred = hrp.Position + hrp.AssemblyLinearVelocity * LEAP_TIME * 0.7
                    local offX, offZ = pred.X - c.pos.X, pred.Z - c.pos.Z
                    local len, maxD = math.sqrt(offX*offX + offZ*offZ), JUMP_RANGE * 1.3
                    if len > maxD then offX, offZ = offX/len*maxD, offZ/len*maxD end
                    startLeap(c, c.pos, V(c.pos.X+offX, hrp.Position.Y - 1.5 + 0.5*S, c.pos.Z+offZ), JUMP_HEIGHT, true)
                end
            end
            
        elseif st == "leap" or st == "return" then
            c.stateT = c.stateT + dt
            local u, h = math.min(1, c.stateT / LEAP_TIME), c.leapH
            c.pos = c.leapFrom:Lerp(c.leapTo, u) + V(0, 4*h*u*(1-u), 0)
            pitch = math.atan2((c.leapTo.Y - c.leapFrom.Y) + 4*h*(1-2*u), c.leapLen)
            fast, swimAmt = 1, 0.6
            if st == "leap" then
                jawT = (u < 0.7) and -1.1 or -0.1
                if u > 0.45 then checkHit(c) end
                if u >= 1 then c.state, c.stateT = "recover", 0 end
            else
                jawT = -0.3
                if u >= 1 then
                    c.state, c.pos, c.lastJump, c.wander, c.idleUntil = "swim", c.homePos, now, nil, now + 1
                end
            end
            
        elseif st == "recover" then
            c.stateT = c.stateT + dt
            jawT, swimAmt = -0.1, 0.5
            local to = c.homePos - c.pos
            faceYaw(c, math.atan2(-to.X, -to.Z), TURN_SPEED * 3, dt)
            if c.stateT >= RECOVER_TIME then startLeap(c, c.pos, c.homePos, JUMP_HEIGHT * 0.6, false) end
        end
        
        c.sw = c.sw + (swimAmt - c.sw) * math.min(1, dt * 4)
        c.phase = c.phase + dt * (1 + c.sw * 12 + fast * 5)
        c.jaw = c.jaw + (jawT - c.jaw) * math.min(1, dt * 14)
        local ph, sw, M, B = c.phase, c.sw, c.M, c.B
        local amp, wk = math.min(1, sw * 3), math.sin(c.phase * 2) -- amp = kekuatan langkah, wk = ritme jalan
        c.root.CFrame = CFrame.new(c.pos) * CFrame.Angles(0, c.yaw, 0) * CFrame.Angles(pitch, 0, 0)
        M.Body.C0 = B.Body * CFrame.new(0, (math.abs(wk)*0.1*amp + math.sin(ph*0.3)*0.04 - dip*0.5) * S, 0) * CFrame.Angles(0, wk*0.05*amp, 0)
        M.Head.C0 = B.Head * CFrame.Angles(dip*0.2, -wk*0.08*amp, 0)
        M.Jaw.C0 = B.Jaw * CFrame.Angles(c.jaw, 0, 0)
        for i = 1, 5 do
            M["Tail"..i].C0 = B["Tail"..i] * CFrame.Angles(0, math.sin(ph*2 + 3 - i*0.6) * (0.04 + 0.12*amp) * (0.6 + 0.25*i), 0)
        end
        for _, sd in ipairs(SIDES) do
            local n, s = sd[1], sd[2]
            for _, tag in ipairs({"F", "B"}) do
                local a = ph*2 + (((tag == "F") == (n == "L")) and 0 or math.pi) -- langkah diagonal
                local lift = math.max(0, -math.cos(a)) * 0.8 * amp
                M["Leg"..tag..n].C0 = B["Leg"..tag..n] * CFrame.Angles(0, -s*(0.4 + math.sin(a)*0.45*amp), 0)
                M["Fore"..tag..n].C0 = B["Fore"..tag..n] * CFrame.Angles(lift, 0, 0)
                M["Foot"..tag..n].C0 = B["Foot"..tag..n] * CFrame.Angles(-lift*0.6, 0, 0)
            end
        end
    end
    
    local crocs = {}
    for i = 1, CROC_COUNT do
        local wp = pickWater()
        local hx, hz = lim(wp)
        local pos = wp.CFrame:PointToWorldSpace(V((math.random()*2-1)*hx, wp.Size.Y/2 + FLOAT*S, (math.random()*2-1)*hz))
        local yaw = rand(0, math.pi * 2)
        local model, root, M, B = buildCroc(CFrame.new(pos) * CFrame.Angles(0, yaw, 0))
        table.insert(crocs, {water = wp, model = model, root = root, M = M, B = B, pos = pos, yaw = yaw,
        state = "swim", stateT = 0, lastJump = -100, idleUntil = 0, nextWander = 0,
        phase = rand(0, 6), sw = 0, jaw = IDLE_JAW, hit = {}})
    end
    print("[Buaya] " .. #crocs .. " buaya dibuat.")
    RunService.Heartbeat:Connect(function(dt)
        local now = os.clock()
        for _, c in ipairs(crocs) do update(c, dt, now) end
    end)