local v local f=game:GetService("\080\108\097\121\101\114\115")function MakeAMove()v=false if tick()-holdOrder<holdDuration then return end if stance=="\119\097\110\100\101\114"then for f,N in next,f:GetPlayers()do if N.Character and N.Character.PrimaryPart then local f=(N.Character.PrimaryPart.CFrame.Position-root.CFrame.Position).Magnitude if f>=500 then v=true break end end end if v then task.wait(math.random(1,1.5))return end local N=Ray.new((root.CFrame*CFrame.new(0,100,-15)).p,Vector3.new(0,-1000,0))local D,i,u,V=workspace:FindPartOnRayWithIgnoreList(N,shark:GetDescendants())if D then if D==workspace.Terrain and V~=Enum.Material.Water then destination=((root.CFrame*CFrame.Angles(0,math.rad(math.random(90,270)),0))*CFrame.new(0,0,-40)).p holdOrder=tick()elseif D==workspace.Terrain and V==Enum.Material.Water then if tick()-lastAdjustment>nextAdjustment then lastAdjustment=tick()nextAdjustment=math.random(10,30)destination=((root.CFrame*CFrame.Angles(0,math.rad(math.random(0,359)),0))*CFrame.new(0,0,-40)).p holdDuration=2 holdOrder=tick()else destination=(root.CFrame*CFrame.new(0,0,-25)).p end end elseif D and D~=workspace.Terrain then destination=(root.CFrame*CFrame.new(0,0,-25)).p elseif not D then destination=((root.CFrame*CFrame.Angles(0,math.rad(180),0))*CFrame.new(0,0,-40)).p holdDuration=4 holdOrder=tick()end bodyPos.Position=Vector3.new(destination.X,-6,destination.Z)bodyGyro.CFrame=CFrame.new((CFrame.new(root.CFrame.p.X,-6,root.CFrame.p.Z)).p,(CFrame.new(destination.X,-6,destination.Z)).p)elseif stance=="\097\116\116\097\099\107"then bodyPos.Position=destination bodyGyro.CFrame=CFrame.new(root.Position,Vector3.new(destination.X,root.Position.Y,destination.Z))if(shark.PrimaryPart.Position-target.PrimaryPart.Position).magnitude<10 then if target.Humanoid.SeatPart then game.ReplicatedStorage.Events.NPCAttack:Fire(target.Humanoid.SeatPart.Parent,math.random(5,15))else game.ReplicatedStorage.Events.NPCAttack:Fire(game.Players:GetPlayerFromCharacter(target),25)end shark.Head.SharkEat:Play()local v=game.ReplicatedStorage.Particles.Teeth:Clone()v.Parent=shark.Head v.EmissionDirection=Enum.NormalId.Top wait()v:Emit(1)holdOrder=tick()holdDuration=2 end end end MakeAMove()local N=coroutine.wrap(function()while true do stance="\119\097\110\100\101\114"local v=workspace:FindPartsInRegion3WithIgnoreList(Region3.new(shark.PrimaryPart.Position+Vector3.new(-60,-3,-60),shark.PrimaryPart.Position+Vector3.new(60,10,60)),shark:GetChildren())for v,f in next,v do if f.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")and f.Parent.Humanoid.Health>0 then local v=Ray.new(f.Position+Vector3.new(0,10,0),Vector3.new(0,-50,0))local N,D,i,u=workspace:FindPartOnRay(v,f.Parent)if N==workspace.Terrain and u~=Enum.Material.Water then else stance="\097\116\116\097\099\107"target=f.Parent destination=(CFrame.new(root.CFrame.p,Vector3.new(f.Parent.PrimaryPart.CFrame.p.x,-9,f.Parent.PrimaryPart.CFrame.p.z))*CFrame.new(0,0,-50)).p break end end end if stance=="\119\097\110\100\101\114"then scanInterval=1 target=nil MakeAMove()elseif stance=="\097\116\116\097\099\107"then scanInterval=.1 MakeAMove()end wait(scanInterval)end end)N()
-- Dark was here.
local nearplayer
local Players = game:GetService("Players")
function MakeAMove()
	nearplayer = false
	if tick() - holdOrder < holdDuration then
		return
	end
	if stance == "wander" then
		for _, Player in next, Players:GetPlayers() do
			if Player.Character and Player.Character.PrimaryPart then
				local dis = (Player.Character.PrimaryPart.CFrame.Position - root.CFrame.Position).Magnitude
				if dis >= 500 then
					nearplayer = true
					break
				end
			end
		end

		if nearplayer then
			task.wait(math.random(1, 1 + 1 / 2))
			return
		end

		local collisionRay = Ray.new((root.CFrame * CFrame.new(0, 100, -15)).p, Vector3.new(0, -1000, 0))
		local part, pos, norm, mat = workspace:FindPartOnRayWithIgnoreList(collisionRay, shark:GetDescendants())
		--local asdf = Instance.new("Part")
		--asdf.Anchored = true
		--asdf.Size = Vector3.new(2,2,2)
		--asdf.CFrame = CFrame.new(pos)
		--asdf.Parent = workspace
		if part then
			if part == workspace.Terrain and mat ~= Enum.Material.Water then
				-- redirect
				destination = ((root.CFrame * CFrame.Angles(0, math.rad(math.random(90, 270)), 0)) * CFrame.new(
					0,
					0,
					-40
				)).p
				holdOrder = tick()
			elseif part == workspace.Terrain and mat == Enum.Material.Water then
				if (tick() - lastAdjustment) > nextAdjustment then
					lastAdjustment = tick()
					nextAdjustment = math.random(10, 30)
					destination = ((root.CFrame * CFrame.Angles(0, math.rad(math.random(0, 359)), 0)) * CFrame.new(
						0,
						0,
						-40
					)).p
					holdDuration = 2
					holdOrder = tick()
				else
					destination = (root.CFrame * CFrame.new(0, 0, -25)).p
				end
			end
		elseif part and part ~= workspace.Terrain then
			destination = (root.CFrame * CFrame.new(0, 0, -25)).p
		elseif not part then
			destination = ((root.CFrame * CFrame.Angles(0, math.rad(180), 0)) * CFrame.new(0, 0, -40)).p
			holdDuration = 4
			holdOrder = tick()
		end
		bodyPos.Position = Vector3.new(destination.X, -6, destination.Z)
		bodyGyro.CFrame = CFrame.new(
			CFrame.new(root.CFrame.p.X, -6, root.CFrame.p.Z).p,
			CFrame.new(destination.X, -6, destination.Z).p
		)
	elseif stance == "attack" then
		bodyPos.Position = destination
		bodyGyro.CFrame = CFrame.new(root.Position, Vector3.new(destination.X, root.Position.Y, destination.Z))

		if (shark.PrimaryPart.Position - target.PrimaryPart.Position).magnitude < 10 then
			-- lunge and hold
			if target.Humanoid.SeatPart then
				game.ReplicatedStorage.Events.NPCAttack:Fire(target.Humanoid.SeatPart.Parent, math.random(5, 15))
			else
				game.ReplicatedStorage.Events.NPCAttack:Fire(game.Players:GetPlayerFromCharacter(target), 25)
			end

			shark.Head.SharkEat:Play()
			local emitter = game.ReplicatedStorage.Particles.Teeth:Clone()
			emitter.Parent = shark.Head
			emitter.EmissionDirection = Enum.NormalId.Top
			wait()
			emitter:Emit(1)

			holdOrder = tick()
			holdDuration = 2
		end
	end
end -- end of MakeAMove()
MakeAMove()

local scanSurroundings = coroutine.wrap(function()
	while true do
		stance = "wander"
		local surroundingParts = workspace:FindPartsInRegion3WithIgnoreList(
			Region3.new(
				shark.PrimaryPart.Position + Vector3.new(-60, -3, -60),
				shark.PrimaryPart.Position + Vector3.new(60, 10, 60)
			),
			shark:GetChildren()
		)
		for _, v in next, surroundingParts do
			if v.Parent:FindFirstChild("Humanoid") and v.Parent.Humanoid.Health > 0 then
				-- we have a player in the radius
				local playerRay = Ray.new(v.Position + Vector3.new(0, 10, 0), Vector3.new(0, -50, 0))
				local part, pos, norm, mat = workspace:FindPartOnRay(playerRay, v.Parent)
				if part == workspace.Terrain and mat ~= Enum.Material.Water then
					-- don't set to attack
				else
					stance = "attack"
					target = v.Parent
					-- destination = v.Parent.PrimaryPart.Position
					destination = (CFrame.new(
						root.CFrame.p,
						Vector3.new(v.Parent.PrimaryPart.CFrame.p.x, -9, v.Parent.PrimaryPart.CFrame.p.z)
					) * CFrame.new(0, 0, -50)).p
					break
					-- change y height of shark
				end
			end
		end

		if stance == "wander" then
			scanInterval = 1
			target = nil
			MakeAMove()
		elseif stance == "attack" then
			scanInterval = 0.1
			MakeAMove()
		end

		wait(scanInterval)
	end -- end of wtd
end)
scanSurroundings()
